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                                                     o.params._is_purchased = 1;
793                                                 }
794                                             },
795                                             remoteSort : true,
796                                             sortInfo : { direction : 'ASC', field: 'item_number' },
797                                             proxy : {
798                                                 xtype: 'HttpProxy',
799                                                 xns: Roo.data,
800                                                 method : 'GET',
801                                                 url : baseURL + '/Roo/itemsite.php'
802                                             },
803                                             reader : {
804                                                 xtype: 'JsonReader',
805                                                 xns: Roo.data,
806                                                 id : 'itemsite_id',
807                                                 root : 'data',
808                                                 totalProperty : 'total',
809                                                 fields : [{"name":"item_id","type":"int"},"item_number"]
810                                             }
811                                         }
812                                     }
813                                 }
814                             },
815                             {
816                                 xtype: 'ColumnModel',
817                                 xns: Roo.grid,
818                                 dataIndex : 'item_descrip1',
819                                 header : 'Item description',
820                                 width : 150,
821                                 renderer : function(v) { return String.format('{0}', v); }
822                             },
823                             {
824                                 xtype: 'ColumnModel',
825                                 xns: Roo.grid,
826                                 dataIndex : 'poitem_duedate',
827                                 header : 'Due date',
828                                 width : 100,
829                                 renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
830                             },
831                             {
832                                 xtype: 'ColumnModel',
833                                 xns: Roo.grid,
834                                 align : 'right',
835                                 dataIndex : 'poitem_qty_ordered',
836                                 header : 'Ordered',
837                                 width : 75,
838                                 renderer : function(v) { return String.format('{0}', v); },
839                                 editor : {
840                                     xtype: 'GridEditor',
841                                     xns: Roo.grid,
842                                     field : {
843                                         xtype: 'NumberField',
844                                         xns: Roo.form,
845                                         allowDecimals : false,
846                                         decimalPrecision : 0,
847                                         minValue : 1,
848                                         style : 'text-align:right'
849                                     }
850                                 }
851                             },
852                             {
853                                 xtype: 'ColumnModel',
854                                 xns: Roo.grid,
855                                 align : 'right',
856                                 dataIndex : 'poitem_qty_received',
857                                 header : 'Received',
858                                 width : 75,
859                                 renderer : function(v,x,r) { 
860                                     return String.format(
861                                         r.data.poitem_qty_ordered != (v-r.data.poitem_qty_returned) ? '<span style="color:red">{0}</span>':  '{0}',
862                                          v - r.data.poitem_qty_returned);
863                                 }
864                             },
865                             {
866                                 xtype: 'ColumnModel',
867                                 xns: Roo.grid,
868                                 align : 'right',
869                                 dataIndex : 'poitem_qty_vouchered',
870                                 header : 'Vouchered',
871                                 width : 65,
872                                 renderer : function(v,x,r) { 
873                                     return String.format(
874                                         r.data.poitem_qty_ordered != v ? '<span style="color:red">{0}</span>':  '{0}',
875                                          v);
876                                 }
877                             },
878                             {
879                                 xtype: 'ColumnModel',
880                                 xns: Roo.grid,
881                                 align : 'right',
882                                 dataIndex : 'poitem_unitprice',
883                                 header : 'Unit price',
884                                 width : 100,
885                                 renderer : function(v) { return String.format('{0}', (v || v == 0) ? parseFloat(v).toFixed(3) : ''); },
886                                 editor : {
887                                     xtype: 'GridEditor',
888                                     xns: Roo.grid,
889                                     field : {
890                                         xtype: 'NumberField',
891                                         xns: Roo.form,
892                                         allowDecimals : false,
893                                         decimalPrecision : 0,
894                                         minValue : 1,
895                                         style : 'text-align:right'
896                                     }
897                                 }
898                             }
899                         ]
900                     }
901                 },
902                 {
903                     xtype: 'NestedLayoutPanel',
904                     xns: Roo,
905                     region : 'center',
906                     title : "TX",
907                     layout : {
908                         xtype: 'BorderLayout',
909                         xns: Roo,
910                         items : [
911                             {
912                                 xtype: 'GridPanel',
913                                 xns: Roo,
914                                 listeners : {
915                                     activate : function() {
916                                         _this.itempanel = this;
917                                         
918                                         
919                                         if (_this.itemgrid) {
920                                             _this.itemgrid.footer.onClick('first');
921                                         }
922                                     }
923                                 },
924                                 background : false,
925                                 fitContainer : true,
926                                 fitToframe : true,
927                                 region : 'center',
928                                 tableName : 'poitem',
929                                 title : "Items",
930                                 grid : {
931                                     xtype: 'Grid',
932                                     xns: Roo.grid,
933                                     listeners : {
934                                         render : function() 
935                                         {
936                                             _this.itemgrid = this; 
937                                             //_this.dialog = Pman.Dialog.FILL_IN
938                                             if (_this.itempanel.active) {
939                                                this.footer.onClick('first');
940                                             }
941                                         },
942                                         rowclick : function (_self, rowIndex, e)
943                                         {
944                                             
945                                             _this.gltransgrid.footer.onClick('first');
946                                         }
947                                     },
948                                     autoExpandColumn : 'item_number',
949                                     loadMask : true,
950                                     toolbar : {
951                                         xtype: 'Toolbar',
952                                         xns: Roo,
953                                         items : [
954                                             {
955                                                 xtype: 'Button',
956                                                 xns: Roo.Toolbar,
957                                                 listeners : {
958                                                     click : function (_self, e)
959                                                     {
960                                                         
961                                                          new Pman.Download({
962                                                             url : baseURL + '/Roo/Metasql',
963                                                             method : 'GET',
964                                                             timeout: 600000,
965                                                             params : {
966                                                                 _group : 'gltrans_stock',
967                                                                 _name : 'byorder',
968                                                                 'pohead_number:text' : _this.form.findField('pohead_number').getValue(),
969                                                                 csvCols : '*',
970                                                                 csvTitles : '*', 
971                                                                 limit : 9999       
972                                                             }
973                                                         });
974                                                     }
975                                                 },
976                                                 text : "PO analysis"
977                                             }
978                                         ]
979                                     },
980                                     sm : {
981                                         xtype: 'RowSelectionModel',
982                                         xns: Roo.grid,
983                                         singleSelect : true
984                                     },
985                                     dataSource : {
986                                         xtype: 'Store',
987                                         xns: Roo.data,
988                                         listeners : {
989                                             beforeload : function (_self, o)
990                                             {
991                                                 o.params = o.params || {};
992                                                 var hid = _this.form.findField('pohead_id').getValue();
993                                                 
994                                                 if(!hid.length){
995                                                     return false;
996                                                 }
997                                                 
998                                                 o.params.poitem_pohead_id = hid;
999                                                 
1000                                                 o.params._with_item = 1;
1001                                                 
1002                                             }
1003                                         },
1004                                         remoteSort : true,
1005                                         sortInfo : { field : 'poitem_id', direction: 'ASC' },
1006                                         proxy : {
1007                                             xtype: 'HttpProxy',
1008                                             xns: Roo.data,
1009                                             method : 'GET',
1010                                             url : baseURL + '/Roo/poitem.php'
1011                                         },
1012                                         reader : {
1013                                             xtype: 'JsonReader',
1014                                             xns: Roo.data,
1015                                             totalProperty : 'total',
1016                                             root : 'data',
1017                                             id : 'id',
1018                                             fields : [
1019                                                 {
1020                                                     'name': 'id',
1021                                                     'type': 'int'
1022                                                 },
1023                                                 {
1024                                                     'name': 'name',
1025                                                     'type': 'string'
1026                                                 },
1027                                                 {
1028                                                     'name': 'type',
1029                                                     'type': 'int'
1030                                                 },
1031                                                 {
1032                                                     'name': 'leader',
1033                                                     'type': 'int'
1034                                                 },
1035                                                 {
1036                                                     'name': 'leader_id',
1037                                                     'type': 'int'
1038                                                 },
1039                                                 {
1040                                                     'name': 'leader_office_id',
1041                                                     'type': 'int'
1042                                                 },
1043                                                 {
1044                                                     'name': 'leader_name',
1045                                                     'type': 'string'
1046                                                 },
1047                                                 {
1048                                                     'name': 'leader_phone',
1049                                                     'type': 'string'
1050                                                 },
1051                                                 {
1052                                                     'name': 'leader_fax',
1053                                                     'type': 'string'
1054                                                 },
1055                                                 {
1056                                                     'name': 'leader_email',
1057                                                     'type': 'string'
1058                                                 },
1059                                                 {
1060                                                     'name': 'leader_company_id',
1061                                                     'type': 'int'
1062                                                 },
1063                                                 {
1064                                                     'name': 'leader_role',
1065                                                     'type': 'string'
1066                                                 },
1067                                                 {
1068                                                     'name': 'leader_active',
1069                                                     'type': 'int'
1070                                                 },
1071                                                 {
1072                                                     'name': 'leader_remarks',
1073                                                     'type': 'string'
1074                                                 },
1075                                                 {
1076                                                     'name': 'leader_passwd',
1077                                                     'type': 'string'
1078                                                 },
1079                                                 {
1080                                                     'name': 'leader_owner_id',
1081                                                     'type': 'int'
1082                                                 },
1083                                                 {
1084                                                     'name': 'leader_lang',
1085                                                     'type': 'string'
1086                                                 },
1087                                                 {
1088                                                     'name': 'leader_no_reset_sent',
1089                                                     'type': 'int'
1090                                                 },
1091                                                 {
1092                                                     'name': 'leader_action_type',
1093                                                     'type': 'string'
1094                                                 },
1095                                                 {
1096                                                     'name': 'leader_project_id',
1097                                                     'type': 'int'
1098                                                 },
1099                                                 {
1100                                                     'name': 'leader_deleted_by',
1101                                                     'type': 'int'
1102                                                 },
1103                                                 {
1104                                                     'name': 'leader_deleted_dt',
1105                                                     'type': 'date'
1106                                                 },
1107                                                 {
1108                                                     'name': 'leader_firstname',
1109                                                     'type': 'string'
1110                                                 },
1111                                                 {
1112                                                     'name': 'leader_lastname',
1113                                                     'type': 'string'
1114                                                 },
1115                                                 {
1116                                                     'name': 'leader_name_facebook',
1117                                                     'type': 'string'
1118                                                 },
1119                                                 {
1120                                                     'name': 'leader_url_blog',
1121                                                     'type': 'string'
1122                                                 },
1123                                                 {
1124                                                     'name': 'leader_url_twitter',
1125                                                     'type': 'string'
1126                                                 },
1127                                                 {
1128                                                     'name': 'leader_url_linkedin',
1129                                                     'type': 'string'
1130                                                 },
1131                                                 {
1132                                                     'name': 'leader_crm_lead_percentage',
1133                                                     'type': 'int'
1134                                                 },
1135                                                 {
1136                                                     'name': 'leader_crm_industry_id',
1137                                                     'type': 'int'
1138                                                 },
1139                                                 {
1140                                                     'name': 'leader_crm_updated_action_id',
1141                                                     'type': 'int'
1142                                                 },
1143                                                 {
1144                                                     'name': 'leader_crm_created_action_id',
1145                                                     'type': 'int'
1146                                                 },
1147                                                 {
1148                                                     'name': 'leader_crm_type_id',
1149                                                     'type': 'int'
1150                                                 }
1151                                             ]
1152                                         }
1153                                     },
1154                                     footer : {
1155                                         xtype: 'PagingToolbar',
1156                                         xns: Roo,
1157                                         displayInfo : false,
1158                                         displayMsg : "Displaying poitem{0} - {1} of {2}",
1159                                         emptyMsg : "No item found",
1160                                         pageSize : 25
1161                                     },
1162                                     colModel : [
1163                                         {
1164                                             xtype: 'ColumnModel',
1165                                             xns: Roo.grid,
1166                                             dataIndex : 'poitem_linenumber',
1167                                             header : 'Line #',
1168                                             width : 25,
1169                                             renderer : function(v) { return String.format('{0}', v); }
1170                                         },
1171                                         {
1172                                             xtype: 'ColumnModel',
1173                                             xns: Roo.grid,
1174                                             dataIndex : 'item_number',
1175                                             header : 'Item #',
1176                                             width : 75,
1177                                             renderer : function(v) { return String.format('{0}', v); }
1178                                         },
1179                                         {
1180                                             xtype: 'ColumnModel',
1181                                             xns: Roo.grid,
1182                                             dataIndex : 'poitem_qty_ordered',
1183                                             header : 'Ordered',
1184                                             width : 50,
1185                                             renderer : function(v) { return String.format('{0}', v); }
1186                                         },
1187                                         {
1188                                             xtype: 'ColumnModel',
1189                                             xns: Roo.grid,
1190                                             dataIndex : 'poitem_qty_received',
1191                                             header : 'Received',
1192                                             width : 50,
1193                                             renderer : function(v,x,r) 
1194                                             {
1195                                                 return String.format('{0}', (v- r.data.poitem_qty_returned)) ;  
1196                                                 
1197                                             }
1198                                         },
1199                                         {
1200                                             xtype: 'ColumnModel',
1201                                             xns: Roo.grid,
1202                                             dataIndex : 'poitem_unitprice',
1203                                             header : 'Unit Price',
1204                                             width : 75,
1205                                             renderer : function(v,x,r) 
1206                                             {
1207                                                  
1208                                                 return String.format('{0}', (v- r.data.poitem_qty_returned) ? parseFloat(v- r.data.poitem_qty_returned).toFixed(3) : '') ;  
1209                                                 
1210                                             }
1211                                         }
1212                                     ]
1213                                 }
1214                             },
1215                             {
1216                                 xtype: 'GridPanel',
1217                                 xns: Roo,
1218                                 listeners : {
1219                                     activate : function() {
1220                                         _this.gltranspanel = this;
1221                                         //if (_this.gltransgrid) {
1222                                         //    _this.gltransgrid.footer.onClick('first');
1223                                         // }
1224                                     }
1225                                 },
1226                                 background : false,
1227                                 fitContainer : true,
1228                                 fitToframe : true,
1229                                 region : 'east',
1230                                 tableName : 'Gltrans',
1231                                 title : "Gltrans",
1232                                 grid : {
1233                                     xtype: 'Grid',
1234                                     xns: Roo.grid,
1235                                     listeners : {
1236                                         render : function() 
1237                                         {
1238                                             _this.gltransgrid = this; 
1239                                             //_this.dialog = Pman.Dialog.FILL_IN
1240                                           //  if (_this.gltranspanel.active) {
1241                                           //     this.footer.onClick('first');
1242                                           //  }
1243                                         }
1244                                     },
1245                                     autoExpandColumn : 'gltrans_notes',
1246                                     loadMask : true,
1247                                     sm : {
1248                                         xtype: 'RowSelectionModel',
1249                                         xns: Roo.grid,
1250                                         singleSelect : true
1251                                     },
1252                                     dataSource : {
1253                                         xtype: 'Store',
1254                                         xns: Roo.data,
1255                                         listeners : {
1256                                             beforeload : function (_self, o)
1257                                             {
1258                                                 o.params = o.params || {};
1259                                                 
1260                                                 var s = _this.itemgrid.getSelectionModel().getSelected();
1261                                                 if(!s){
1262                                                     Roo.MessageBox.alert('Error', 'Please select a item');
1263                                                     return false;
1264                                                 }
1265                                                 
1266                                                 o.params._poview = 1;
1267                                                 o.params.gltrans_deleted = 0;
1268                                                 o.params.gltrans_doctype = 'PO';
1269                                                 o.params._linenumber = s.data.poitem_linenumber;
1270                                                 o.params._item = s.data.item_number;
1271                                                 o.params._ponumber = _this.form.findField('pohead_number').getValue();
1272                                                 
1273                                             }
1274                                         },
1275                                         remoteSort : true,
1276                                         sortInfo : { field : 'gltrans_id', direction: 'ASC' },
1277                                         proxy : {
1278                                             xtype: 'HttpProxy',
1279                                             xns: Roo.data,
1280                                             method : 'GET',
1281                                             url : baseURL + '/Roo/gltrans.php'
1282                                         },
1283                                         reader : {
1284                                             xtype: 'JsonReader',
1285                                             xns: Roo.data,
1286                                             totalProperty : 'total',
1287                                             root : 'data',
1288                                             id : 'id',
1289                                             fields : [
1290                                                 {
1291                                                     'name': 'id',
1292                                                     'type': 'int'
1293                                                 },
1294                                                 {
1295                                                     'name': 'name',
1296                                                     'type': 'string'
1297                                                 },
1298                                                 {
1299                                                     'name': 'type',
1300                                                     'type': 'int'
1301                                                 },
1302                                                 {
1303                                                     'name': 'leader',
1304                                                     'type': 'int'
1305                                                 },
1306                                                 {
1307                                                     'name': 'leader_id',
1308                                                     'type': 'int'
1309                                                 },
1310                                                 {
1311                                                     'name': 'leader_office_id',
1312                                                     'type': 'int'
1313                                                 },
1314                                                 {
1315                                                     'name': 'leader_name',
1316                                                     'type': 'string'
1317                                                 },
1318                                                 {
1319                                                     'name': 'leader_phone',
1320                                                     'type': 'string'
1321                                                 },
1322                                                 {
1323                                                     'name': 'leader_fax',
1324                                                     'type': 'string'
1325                                                 },
1326                                                 {
1327                                                     'name': 'leader_email',
1328                                                     'type': 'string'
1329                                                 },
1330                                                 {
1331                                                     'name': 'leader_company_id',
1332                                                     'type': 'int'
1333                                                 },
1334                                                 {
1335                                                     'name': 'leader_role',
1336                                                     'type': 'string'
1337                                                 },
1338                                                 {
1339                                                     'name': 'leader_active',
1340                                                     'type': 'int'
1341                                                 },
1342                                                 {
1343                                                     'name': 'leader_remarks',
1344                                                     'type': 'string'
1345                                                 },
1346                                                 {
1347                                                     'name': 'leader_passwd',
1348                                                     'type': 'string'
1349                                                 },
1350                                                 {
1351                                                     'name': 'leader_owner_id',
1352                                                     'type': 'int'
1353                                                 },
1354                                                 {
1355                                                     'name': 'leader_lang',
1356                                                     'type': 'string'
1357                                                 },
1358                                                 {
1359                                                     'name': 'leader_no_reset_sent',
1360                                                     'type': 'int'
1361                                                 },
1362                                                 {
1363                                                     'name': 'leader_action_type',
1364                                                     'type': 'string'
1365                                                 },
1366                                                 {
1367                                                     'name': 'leader_project_id',
1368                                                     'type': 'int'
1369                                                 },
1370                                                 {
1371                                                     'name': 'leader_deleted_by',
1372                                                     'type': 'int'
1373                                                 },
1374                                                 {
1375                                                     'name': 'leader_deleted_dt',
1376                                                     'type': 'date'
1377                                                 },
1378                                                 {
1379                                                     'name': 'leader_firstname',
1380                                                     'type': 'string'
1381                                                 },
1382                                                 {
1383                                                     'name': 'leader_lastname',
1384                                                     'type': 'string'
1385                                                 },
1386                                                 {
1387                                                     'name': 'leader_name_facebook',
1388                                                     'type': 'string'
1389                                                 },
1390                                                 {
1391                                                     'name': 'leader_url_blog',
1392                                                     'type': 'string'
1393                                                 },
1394                                                 {
1395                                                     'name': 'leader_url_twitter',
1396                                                     'type': 'string'
1397                                                 },
1398                                                 {
1399                                                     'name': 'leader_url_linkedin',
1400                                                     'type': 'string'
1401                                                 },
1402                                                 {
1403                                                     'name': 'leader_crm_lead_percentage',
1404                                                     'type': 'int'
1405                                                 },
1406                                                 {
1407                                                     'name': 'leader_crm_industry_id',
1408                                                     'type': 'int'
1409                                                 },
1410                                                 {
1411                                                     'name': 'leader_crm_updated_action_id',
1412                                                     'type': 'int'
1413                                                 },
1414                                                 {
1415                                                     'name': 'leader_crm_created_action_id',
1416                                                     'type': 'int'
1417                                                 },
1418                                                 {
1419                                                     'name': 'leader_crm_type_id',
1420                                                     'type': 'int'
1421                                                 }
1422                                             ]
1423                                         }
1424                                     },
1425                                     footer : {
1426                                         xtype: 'PagingToolbar',
1427                                         xns: Roo,
1428                                         displayInfo : true,
1429                                         displayMsg : "Displaying gltrans{0} - {1} of {2}",
1430                                         emptyMsg : "No gltrans found",
1431                                         pageSize : 25
1432                                     },
1433                                     toolbar : {
1434                                         xtype: 'Toolbar',
1435                                         xns: Roo,
1436                                         items : [
1437                                             {
1438                                                 xtype: 'Fill',
1439                                                 xns: Roo.Toolbar
1440                                             },
1441                                             {
1442                                                 xtype: 'Button',
1443                                                 xns: Roo.Toolbar,
1444                                                 listeners : {
1445                                                     click : function()
1446                                                     {
1447                                                         var pohead_number = _this.form.findField('pohead_number').getValue();
1448                                                         var pohead_id = _this.form.findField('pohead_id').getValue();
1449                                                             
1450                                                         var addv = function(){
1451                                                             new Pman.Request({
1452                                                                 url : baseURL + '/Roo/pohead.php',
1453                                                                 method :'POST',
1454                                                                 params : {
1455                                                                     pohead_id : pohead_id,
1456                                                                     _variance : 1
1457                                                                     
1458                                                                 },
1459                                                                 success : function(res) {
1460                                                                     Roo.MessageBox.alert('Notice', 'DONE');
1461                                                                 }
1462                                                             });
1463                                                         }
1464                                                         
1465                                                         Roo.MessageBox.confirm(
1466                                                             "Confirm",
1467                                                             "Are you sure to add all the variance for " + pohead_number + " ?",
1468                                                             function(r) {
1469                                                                 if (r != 'yes') {
1470                                                                     return;
1471                                                                 }
1472                                                     
1473                                                                 addv();
1474                                                                 return;
1475                                                             }
1476                                                         ); 
1477                                                         
1478                                                         
1479                                                     }
1480                                                 },
1481                                                 cls : 'x-btn-text-icon',
1482                                                 text : "Add All Variance",
1483                                                 icon : Roo.rootURL + 'images/default/tree/leaf.gif'
1484                                             },
1485                                             {
1486                                                 xtype: 'Button',
1487                                                 xns: Roo.Toolbar,
1488                                                 listeners : {
1489                                                     click : function()
1490                                                     {
1491                                                         var s = _this.gltransgrid.getSelectionModel().getSelected();
1492                                                         
1493                                                         if(!s){
1494                                                             Roo.MessageBox.alert('Error','Please select a transaction');
1495                                                             return;
1496                                                         }
1497                                                         
1498                                                         if(s.data.gltrans_misc_id == -1){
1499                                                             Roo.MessageBox.alert('Error','Please select a transaction not variance');
1500                                                             return;
1501                                                         }
1502                                                         
1503                                                         var addit = function(){
1504                                                             new Pman.Request({
1505                                                                 url : baseURL + '/Roo/Gltrans.php',
1506                                                                 method :'POST',
1507                                                                 params : {
1508                                                                     gltrans_id : s.data.gltrans_id,
1509                                                                     _variance : 1
1510                                                                     
1511                                                                 },
1512                                                                 success : function(res) {
1513                                                                     if(res.data == 0){
1514                                                                         Roo.MessageBox.alert('Error','Variance already exist');
1515                                                                     }
1516                                                                     _this.gltransgrid.footer.onClick('refresh');
1517                                                                     
1518                                                                 }
1519                                                             });
1520                                                         }
1521                                                         
1522                                                         Roo.MessageBox.confirm(
1523                                                             "Confirm",
1524                                                             "Are you sure to add a variance ?",
1525                                                             function(r) {
1526                                                                 if (r != 'yes') {
1527                                                                     return;
1528                                                                 }
1529                                                     
1530                                                                 addit();
1531                                                                 return;
1532                                                             }
1533                                                         ); 
1534                                                         
1535                                                         
1536                                                     }
1537                                                 },
1538                                                 cls : 'x-btn-text-icon',
1539                                                 text : "Add Variance",
1540                                                 icon : Roo.rootURL + 'images/default/tree/leaf.gif'
1541                                             },
1542                                             {
1543                                                 xtype: 'Button',
1544                                                 xns: Roo.Toolbar,
1545                                                 listeners : {
1546                                                     click : function()
1547                                                     {
1548                                                         var s = _this.gltransgrid.getSelectionModel().getSelected();
1549                                                         
1550                                                         if(!s){
1551                                                             Roo.MessageBox.alert('Error','Please select a transaction');
1552                                                             return;
1553                                                         }
1554                                                         
1555                                                         if(s.data.gltrans_misc_id != -1){
1556                                                             Roo.MessageBox.alert('Error','Just allow to delete the variance');
1557                                                             return;
1558                                                         }
1559                                                         
1560                                                         var delit = function(){
1561                                                             new Pman.Request({
1562                                                                 url : baseURL + '/Roo/Gltrans.php',
1563                                                                 method :'POST',
1564                                                                 params : {
1565                                                                     gltrans_id : s.data.gltrans_id,
1566                                                                     _del : 1
1567                                                                     
1568                                                                 },
1569                                                                 success : function(res) {
1570                                                                     _this.gltransgrid.footer.onClick('refresh');
1571                                                                     
1572                                                                 }
1573                                                             });
1574                                                         }
1575                                                         
1576                                                         Roo.MessageBox.confirm(
1577                                                             "Confirm",
1578                                                             "Are you sure to delete ?",
1579                                                             function(r) {
1580                                                                 if (r != 'yes') {
1581                                                                     return;
1582                                                                 }
1583                                                     
1584                                                                 delit();
1585                                                                 return;
1586                                                             }
1587                                                         ); 
1588                                                         
1589                                                         
1590                                                     }
1591                                                 },
1592                                                 cls : 'x-btn-text-icon',
1593                                                 text : "Delete Variance",
1594                                                 icon : rootURL + '/Pman/templates/images/trash.gif'
1595                                             },
1596                                             {
1597                                                 xtype: 'Button',
1598                                                 xns: Roo.Toolbar,
1599                                                 listeners : {
1600                                                     click : function()
1601                                                     {
1602                                                         var pohead_number = _this.form.findField('pohead_number').getValue();
1603                                                         var pohead_id = _this.form.findField('pohead_id').getValue();
1604                                                             
1605                                                         var fixit = function(){
1606                                                             new Pman.Request({
1607                                                                 url : baseURL + '/Roo/pohead.php',
1608                                                                 method :'POST',
1609                                                                 params : {
1610                                                                     pohead_id : pohead_id,
1611                                                                     _unitcost : 1
1612                                                                     
1613                                                                 },
1614                                                                 success : function(res) {
1615                                                                     Roo.MessageBox.alert('Notice', 'DONE');
1616                                                                 }
1617                                                             });
1618                                                         }
1619                                                         
1620                                                         Roo.MessageBox.confirm(
1621                                                             "Confirm",
1622                                                             "Are you sure to fix the unit cost of " + pohead_number + " ?",
1623                                                             function(r) {
1624                                                                 if (r != 'yes') {
1625                                                                     return;
1626                                                                 }
1627                                                     
1628                                                                 fixit();
1629                                                                 return;
1630                                                             }
1631                                                         ); 
1632                                                         
1633                                                         
1634                                                     }
1635                                                 },
1636                                                 cls : 'x-btn-text-icon',
1637                                                 text : "Fix Unit Cost",
1638                                                 icon : rootURL + '/Pman/templates/images/trash.gif'
1639                                             },
1640                                             {
1641                                                 xtype: 'Button',
1642                                                 xns: Roo.Toolbar,
1643                                                 listeners : {
1644                                                     click : function()
1645                                                     {
1646                                                         var pohead_number = _this.form.findField('pohead_number').getValue();
1647                                                         var pohead_id = _this.form.findField('pohead_id').getValue();
1648                                                             
1649                                                         var delv = function(){
1650                                                             new Pman.Request({
1651                                                                 url : baseURL + '/Roo/pohead.php',
1652                                                                 method :'POST',
1653                                                                 params : {
1654                                                                     pohead_id : pohead_id,
1655                                                                     _del : 1
1656                                                                     
1657                                                                 },
1658                                                                 success : function(res) {
1659                                                                     Roo.MessageBox.alert('Notice', 'DONE');
1660                                                                 }
1661                                                             });
1662                                                         }
1663                                                         
1664                                                         Roo.MessageBox.confirm(
1665                                                             "Confirm",
1666                                                             "Are you sure to delete the variance on voucher of " + pohead_number + " ?",
1667                                                             function(r) {
1668                                                                 if (r != 'yes') {
1669                                                                     return;
1670                                                                 }
1671                                                     
1672                                                                 delv();
1673                                                                 return;
1674                                                             }
1675                                                         ); 
1676                                                         
1677                                                         
1678                                                     }
1679                                                 },
1680                                                 cls : 'x-btn-text-icon',
1681                                                 text : "Delete Varinace on voucher",
1682                                                 icon : rootURL + '/Pman/templates/images/trash.gif'
1683                                             }
1684                                         ]
1685                                     },
1686                                     colModel : [
1687                                         {
1688                                             xtype: 'ColumnModel',
1689                                             xns: Roo.grid,
1690                                             dataIndex : 'gltrans_id',
1691                                             header : 'ID',
1692                                             width : 50,
1693                                             renderer : function(v) { return String.format('{0}', v); }
1694                                         },
1695                                         {
1696                                             xtype: 'ColumnModel',
1697                                             xns: Roo.grid,
1698                                             dataIndex : 'gltrans_date',
1699                                             header : 'Date',
1700                                             width : 75,
1701                                             renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }
1702                                         },
1703                                         {
1704                                             xtype: 'ColumnModel',
1705                                             xns: Roo.grid,
1706                                             dataIndex : 'gltrans_docnumber',
1707                                             header : 'doc #',
1708                                             width : 80,
1709                                             renderer : function(v) { return String.format('{0}', v); }
1710                                         },
1711                                         {
1712                                             xtype: 'ColumnModel',
1713                                             xns: Roo.grid,
1714                                             dataIndex : 'gltrans_amount',
1715                                             header : 'Amount',
1716                                             width : 100,
1717                                             renderer : function(v) { return String.format('{0}', v); }
1718                                         },
1719                                         {
1720                                             xtype: 'ColumnModel',
1721                                             xns: Roo.grid,
1722                                             dataIndex : 'gltrans_notes',
1723                                             header : 'Notes',
1724                                             width : 100,
1725                                             renderer : function(v) { return String.format('{0}', v); }
1726                                         }
1727                                     ]
1728                                 }
1729                             }
1730                         ],
1731                         center : {
1732                             xtype: 'LayoutRegion',
1733                             xns: Roo
1734                         },
1735                         east : {
1736                             xtype: 'LayoutRegion',
1737                             xns: Roo,
1738                             split : true,
1739                             width : 550
1740                         }
1741                     }
1742                 },
1743                 {
1744                     xtype: 'NestedLayoutPanel',
1745                     xns: Roo,
1746                     region : 'center',
1747                     title : "GL Tx",
1748                     layout : {
1749                         xtype: 'BorderLayout',
1750                         xns: Roo,
1751                         items : [
1752                             {
1753                                 xtype: 'GridPanel',
1754                                 xns: Roo,
1755                                 listeners : {
1756                                     activate : function() {
1757                                         _this.gltxpanel = this;
1758                                         if (_this.gltxgrid) {
1759                                             _this.gltxgrid.footer.onClick('first');
1760                                         }
1761                                     }
1762                                 },
1763                                 background : false,
1764                                 fitContainer : true,
1765                                 fitToframe : true,
1766                                 region : 'center',
1767                                 tableName : 'invdetail',
1768                                 title : "invdetail",
1769                                 grid : {
1770                                     xtype: 'Grid',
1771                                     xns: Roo.grid,
1772                                     listeners : {
1773                                         render : function() 
1774                                         {
1775                                             _this.gltxgrid = this; 
1776                                             //_this.dialog = Pman.Dialog.FILL_IN
1777                                             if (_this.gltxpanel.active) {
1778                                                this.footer.onClick('first');
1779                                             }
1780                                         },
1781                                         cellclick : function (_self, rowIndex, columnIndex, e)
1782                                         {
1783                                             if (columnIndex > 0) {
1784                                                 return;
1785                                             }
1786                                             var rec = this.ds.getAt(rowIndex);
1787                                             rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
1788                                             _this.gltxdgrid.footer.onClick('first');
1789                                         }
1790                                     },
1791                                     autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
1792                                     loadMask : true,
1793                                     sm : {
1794                                         xtype: 'RowSelectionModel',
1795                                         xns: Roo.grid,
1796                                         listeners : {
1797                                             selectionchange : function (_self)
1798                                             {
1799                                                 _this.gltxdgrid.footer.onClick('first');;
1800                                             }
1801                                         },
1802                                         singleSelect : true
1803                                     },
1804                                     dataSource : {
1805                                         xtype: 'Store',
1806                                         xns: Roo.data,
1807                                         listeners : {
1808                                             beforeload : function (_self, o)
1809                                             {
1810                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
1811                                                 if (! o.params.pohead_id ) {
1812                                                     this.removeAll();
1813                                                     return false;
1814                                                 }
1815                                                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
1816                                             }
1817                                         },
1818                                         remoteSort : true,
1819                                         sortInfo : { field : 'item_number', direction: 'ASC' },
1820                                         proxy : {
1821                                             xtype: 'HttpProxy',
1822                                             xns: Roo.data,
1823                                             method : 'GET',
1824                                             url : baseURL + '/Roo/gltrans.php'
1825                                         },
1826                                         reader : {
1827                                             xtype: 'JsonReader',
1828                                             xns: Roo.data,
1829                                             totalProperty : 'total',
1830                                             root : 'data',
1831                                             id : 'id',
1832                                             fields : [
1833                                                 {
1834                                                     'name': 'invdetail_id',
1835                                                     'type': 'int'
1836                                                 },
1837                                                 {
1838                                                     'name': 'invdetail_transtype',
1839                                                     'type': 'string'
1840                                                 },
1841                                                 {
1842                                                     'name': 'invdetail_invhist_id',
1843                                                     'type': 'int'
1844                                                 },
1845                                                 {
1846                                                     'name': 'invdetail_location_id',
1847                                                     'type': 'int'
1848                                                 },
1849                                                 {
1850                                                     'name': 'invdetail_qty',
1851                                                     'type': 'float'
1852                                                 },
1853                                                 {
1854                                                     'name': 'invdetail_comments',
1855                                                     'type': 'string'
1856                                                 },
1857                                                 {
1858                                                     'name': 'invdetail_qty_before',
1859                                                     'type': 'float'
1860                                                 },
1861                                                 {
1862                                                     'name': 'invdetail_qty_after',
1863                                                     'type': 'float'
1864                                                 },
1865                                                 {
1866                                                     'name': 'invdetail_invcitem_id',
1867                                                     'type': 'int'
1868                                                 },
1869                                                 {
1870                                                     'name': 'invdetail_expiration',
1871                                                     'type': 'date',
1872                                                     'dateFormat': 'Y-m-d'
1873                                                 },
1874                                                 {
1875                                                     'name': 'invdetail_warrpurc',
1876                                                     'type': 'date',
1877                                                     'dateFormat': 'Y-m-d'
1878                                                 },
1879                                                 {
1880                                                     'name': 'invdetail_ls_id',
1881                                                     'type': 'int'
1882                                                 }
1883                                             ]
1884                                         }
1885                                     },
1886                                     footer : {
1887                                         xtype: 'PagingToolbar',
1888                                         xns: Roo,
1889                                         displayInfo : true,
1890                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
1891                                         emptyMsg : "No invdetail found",
1892                                         pageSize : 9999,
1893                                         items : [
1894                                             {
1895                                                 xtype: 'Button',
1896                                                 xns: Roo.Toolbar,
1897                                                 listeners : {
1898                                                     render : function (_self)
1899                                                     {
1900                                                         _this.glsalesbtn = _self;
1901                                                     },
1902                                                     click : function (_self, e)
1903                                                     {
1904                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
1905                                                     }
1906                                                 },
1907                                                 enableToggle : true,
1908                                                 pressed : true,
1909                                                 text : "Split sales"
1910                                             }
1911                                         ]
1912                                     },
1913                                     colModel : [
1914                                         {
1915                                             xtype: 'ColumnModel',
1916                                             xns: Roo.grid,
1917                                             dataIndex : 'gltrans_as_summary',
1918                                             header : 'Summary',
1919                                             width : 50,
1920                                             renderer : function(v,x,r) { 
1921                                                 
1922                                                 var state = v*1   ?  '-checked' : '';
1923                                                                                 
1924                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1925                                              }
1926                                         },
1927                                         {
1928                                             xtype: 'ColumnModel',
1929                                             xns: Roo.grid,
1930                                             dataIndex : 'gltrans_accnt_id_accnt_descrip',
1931                                             header : 'Account',
1932                                             width : 75,
1933                                             renderer : function(v) { return String.format('{0}', v); }
1934                                         },
1935                                         {
1936                                             xtype: 'ColumnModel',
1937                                             xns: Roo.grid,
1938                                             align : 'right',
1939                                             dataIndex : 'gltrans_amount_credit',
1940                                             header : 'Credit',
1941                                             width : 75,
1942                                             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }
1943                                         },
1944                                         {
1945                                             xtype: 'ColumnModel',
1946                                             xns: Roo.grid,
1947                                             align : 'right',
1948                                             dataIndex : 'gltrans_amount_debit',
1949                                             header : 'Debit',
1950                                             width : 75,
1951                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
1952                                         },
1953                                         {
1954                                             xtype: 'ColumnModel',
1955                                             xns: Roo.grid,
1956                                             align : 'right',
1957                                             dataIndex : 'gltrans_amount_total',
1958                                             header : 'Sum',
1959                                             width : 75,
1960                                             renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }
1961                                         },
1962                                         {
1963                                             xtype: 'ColumnModel',
1964                                             xns: Roo.grid,
1965                                             align : 'right',
1966                                             dataIndex : 'gltrans_amount_total_unposted',
1967                                             header : 'Unposted',
1968                                             width : 75,
1969                                             renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); }
1970                                         }
1971                                     ]
1972                                 }
1973                             },
1974                             {
1975                                 xtype: 'GridPanel',
1976                                 xns: Roo,
1977                                 listeners : {
1978                                     activate : function() {
1979                                         _this.gltxdpanel = this;
1980                                         if (_this.gltxdgrid) {
1981                                             _this.gltxdgrid.footer.onClick('first');
1982                                         }
1983                                     }
1984                                 },
1985                                 background : false,
1986                                 fitContainer : true,
1987                                 fitToframe : true,
1988                                 region : 'east',
1989                                 tableName : 'invdetail',
1990                                 title : "invdetail",
1991                                 grid : {
1992                                     xtype: 'Grid',
1993                                     xns: Roo.grid,
1994                                     listeners : {
1995                                         render : function() 
1996                                         {
1997                                             _this.gltxdgrid = this; 
1998                                             //_this.dialog = Pman.Dialog.FILL_IN
1999                                             if (_this.gltxdpanel.active) {
2000                                                this.footer.onClick('first');
2001                                             }
2002                                         },
2003                                         cellclick : function (_self, ri, ci, e)
2004                                         {
2005                                             
2006                                               var deleteSel = function() {
2007                                             
2008                                                 new Pman.Request({
2009                                                     mask : "Reversing",
2010                                                     url : baseURL + '/Roo/gltrans',
2011                                                     method : 'POST',
2012                                                     params : {  
2013                                                         _void : 1,
2014                                                         gltrans_id : rec.data.gltrans_id
2015                                                         
2016                                                     }, 
2017                                                     success : function() {
2018                                                         rec.set('gltrans_posted', false);
2019                                                         rec.set('gltrans_deleted', true);
2020                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2021                                                        _this.gltxgrid.footer.onClick('first');
2022                                                     }
2023                                                 });
2024                                             
2025                                             }
2026                                             var undeleteSel = function() {
2027                                             
2028                                                 new Pman.Request({
2029                                                     mask : "Reversing",
2030                                                     url : baseURL + '/Roo/gltrans',
2031                                                     method : 'POST',
2032                                                     params : {  
2033                                                         _unvoid : 1,
2034                                                         gltrans_id : rec.data.gltrans_id
2035                                                         
2036                                                     }, 
2037                                                     success : function() {
2038                                                         rec.set('gltrans_posted', true);
2039                                                         rec.set('gltrans_deleted', false);
2040                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2041                                                        _this.gltxgrid.footer.onClick('first');
2042                                                     }
2043                                                 });
2044                                             
2045                                             }
2046                                             
2047                                             var di = this.colModel.config[ci].dataIndex;
2048                                             if (di != 'gltrans_posted') {
2049                                                 return;
2050                                             }
2051                                             
2052                                             
2053                                             
2054                                             var rec = this.ds.getAt(ri);
2055                                             if (rec.data.gltrans_deleted) {
2056                                             
2057                                                  Roo.MessageBox.confirm(
2058                                                     "Confirm", 
2059                                                     "This should only be used by System Administrators - are you sure you know what you are doing!",
2060                                                     function(x) {
2061                                                         if (x != 'yes') {
2062                                                             return;
2063                                                         }
2064                                                         undeleteSel();
2065                                                     }
2066                                                 );
2067                                             
2068                                                 return false;
2069                                             }
2070                                         
2071                                             
2072                                             
2073                                             if (!rec.data.gltrans_posted) {
2074                                         
2075                                                 
2076                                                 
2077                                                 new Pman.Request({
2078                                                     method : 'POST',
2079                                                     url : baseURL + '/Roo/gltrans',
2080                                                     mask : "Posting",
2081                                                     params : {
2082                                                         _post : 1,
2083                                                         gltrans_id : rec.data.gltrans_id
2084                                                     },
2085                                                     success : function (res)
2086                                                     {
2087                                                         rec.set('gltrans_posted', true);
2088                                                         _this.gltxgrid.footer.onClick('first');
2089                                                     
2090                                                     }
2091                                                 
2092                                                 
2093                                                 });
2094                                                 return;
2095                                             }
2096                                             
2097                                             // we have a posted transaction.
2098                                             // only allow recalled to be deleted..
2099                                             if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
2100                                                 return false;
2101                                             }
2102                                             
2103                                             
2104                                          
2105                                             
2106                                             
2107                                         
2108                                             Roo.MessageBox.confirm(
2109                                                 "Confirm", 
2110                                                 "This should only be used by System Administrators - are you sure you know what you are doing!",
2111                                                 function(x) {
2112                                                     if (x != 'yes') {
2113                                                         return;
2114                                                     }
2115                                                     deleteSel();
2116                                                 }
2117                                             );
2118                                                   
2119                                             
2120                                             
2121                                         }
2122                                     },
2123                                     autoExpandColumn : 'gltrans_notes',
2124                                     loadMask : true,
2125                                     dataSource : {
2126                                         xtype: 'Store',
2127                                         xns: Roo.data,
2128                                         listeners : {
2129                                             beforeload : function (_self, o)
2130                                             {
2131                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
2132                                                 var s = _this.gltxgrid.selModel.getSelected();
2133                                                 if (!s) { 
2134                                                     this.removeAll();
2135                                                     return false;
2136                                                 }
2137                                                 o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
2138                                                 o.params.gltrans_is_ship = s.data.gltrans_is_ship;
2139                                                 o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
2140                                                  o.params._hide_void = _this.glvoidshow.pressed ? 1 : 0;
2141                                                 //glvoidshow
2142                                                 
2143                                             }
2144                                         },
2145                                         remoteSort : true,
2146                                         sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
2147                                         proxy : {
2148                                             xtype: 'HttpProxy',
2149                                             xns: Roo.data,
2150                                             method : 'GET',
2151                                             url : baseURL + '/Roo/gltrans.php'
2152                                         },
2153                                         reader : {
2154                                             xtype: 'JsonReader',
2155                                             xns: Roo.data,
2156                                             totalProperty : 'total',
2157                                             root : 'data',
2158                                             id : 'id',
2159                                             fields : [
2160                                                 {
2161                                                     'name': 'invdetail_id',
2162                                                     'type': 'int'
2163                                                 },
2164                                                 {
2165                                                     'name': 'invdetail_transtype',
2166                                                     'type': 'string'
2167                                                 },
2168                                                 {
2169                                                     'name': 'invdetail_invhist_id',
2170                                                     'type': 'int'
2171                                                 },
2172                                                 {
2173                                                     'name': 'invdetail_location_id',
2174                                                     'type': 'int'
2175                                                 },
2176                                                 {
2177                                                     'name': 'invdetail_qty',
2178                                                     'type': 'float'
2179                                                 },
2180                                                 {
2181                                                     'name': 'invdetail_comments',
2182                                                     'type': 'string'
2183                                                 },
2184                                                 {
2185                                                     'name': 'invdetail_qty_before',
2186                                                     'type': 'float'
2187                                                 },
2188                                                 {
2189                                                     'name': 'invdetail_qty_after',
2190                                                     'type': 'float'
2191                                                 },
2192                                                 {
2193                                                     'name': 'invdetail_invcitem_id',
2194                                                     'type': 'int'
2195                                                 },
2196                                                 {
2197                                                     'name': 'invdetail_expiration',
2198                                                     'type': 'date',
2199                                                     'dateFormat': 'Y-m-d'
2200                                                 },
2201                                                 {
2202                                                     'name': 'invdetail_warrpurc',
2203                                                     'type': 'date',
2204                                                     'dateFormat': 'Y-m-d'
2205                                                 },
2206                                                 {
2207                                                     'name': 'invdetail_ls_id',
2208                                                     'type': 'int'
2209                                                 }
2210                                             ]
2211                                         }
2212                                     },
2213                                     footer : {
2214                                         xtype: 'PagingToolbar',
2215                                         xns: Roo,
2216                                         displayInfo : true,
2217                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2218                                         emptyMsg : "No invdetail found",
2219                                         pageSize : 9999,
2220                                         items : [
2221                                             {
2222                                                 xtype: 'Button',
2223                                                 xns: Roo.Toolbar,
2224                                                 listeners : {
2225                                                     click : function (_self, e)
2226                                                     {
2227                                                         new Pman.Download( {
2228                                                             grid : _this.gltxdgrid
2229                                                         
2230                                                         });
2231                                                     }
2232                                                 },
2233                                                 text : "Download"
2234                                             },
2235                                             {
2236                                                 xtype: 'Button',
2237                                                 xns: Roo.Toolbar,
2238                                                 listeners : {
2239                                                     render : function (_self)
2240                                                     {
2241                                                         _this.glvoidshow = _self;
2242                                                     },
2243                                                     click : function (_self, e)
2244                                                     {
2245                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2246                                                     }
2247                                                 },
2248                                                 enableToggle : true,
2249                                                 pressed : true,
2250                                                 text : "Hide Void"
2251                                             }
2252                                         ]
2253                                     },
2254                                     colModel : [
2255                                         {
2256                                             xtype: 'ColumnModel',
2257                                             xns: Roo.grid,
2258                                             dataIndex : 'gltrans_id',
2259                                             header : 'Ref#',
2260                                             sortable : true,
2261                                             width : 75,
2262                                             renderer : function(v) { return String.format('{0}', v ); }
2263                                         },
2264                                         {
2265                                             xtype: 'ColumnModel',
2266                                             xns: Roo.grid,
2267                                             dataIndex : 'gltrans_date',
2268                                             header : 'Date',
2269                                             width : 75,
2270                                             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
2271                                         },
2272                                         {
2273                                             xtype: 'ColumnModel',
2274                                             xns: Roo.grid,
2275                                             dataIndex : 'gltrans_docnumber',
2276                                             header : 'Doc#',
2277                                             width : 75,
2278                                             renderer : function(v,x,r) { 
2279                                                 if (r.data.gltrans_deleted) {
2280                                                    return String.format('<s>{0}</s>', v);     
2281                                                 }
2282                                                 return String.format('{0}', v); 
2283                                             }
2284                                         },
2285                                         {
2286                                             xtype: 'ColumnModel',
2287                                             xns: Roo.grid,
2288                                             dataIndex : 'gltrans_source',
2289                                             header : 'Source',
2290                                             width : 50,
2291                                             renderer : function(v) { return String.format('{0}', v); }
2292                                         },
2293                                         {
2294                                             xtype: 'ColumnModel',
2295                                             xns: Roo.grid,
2296                                             dataIndex : 'gltrans_notes',
2297                                             header : 'Notes',
2298                                             width : 75,
2299                                             renderer : function(v) { return String.format('{0}', v); }
2300                                         },
2301                                         {
2302                                             xtype: 'ColumnModel',
2303                                             xns: Roo.grid,
2304                                             align : 'right',
2305                                             dataIndex : 'gltrans_amount',
2306                                             header : 'Amount',
2307                                             width : 75,
2308                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2309                                         },
2310                                         {
2311                                             xtype: 'ColumnModel',
2312                                             xns: Roo.grid,
2313                                             dataIndex : 'gltrans_posted',
2314                                             header : 'Posted',
2315                                             width : 50,
2316                                             renderer : function(v,x,r) { 
2317                                                 
2318                                                 var state = v   ?  '-checked' : '';
2319                                                                                 
2320                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2321                                              }
2322                                         }
2323                                     ]
2324                                 }
2325                             }
2326                         ],
2327                         center : {
2328                             xtype: 'LayoutRegion',
2329                             xns: Roo
2330                         },
2331                         east : {
2332                             xtype: 'LayoutRegion',
2333                             xns: Roo,
2334                             split : true,
2335                             width : 500
2336                         }
2337                     }
2338                 }
2339             ],
2340             center : {
2341                 xtype: 'LayoutRegion',
2342                 xns: Roo,
2343                 alwaysShowTabs : true,
2344                 tabPosition : 'top',
2345                 toolbar : {
2346                     xtype: 'Toolbar',
2347                     xns: Roo,
2348                     items : [
2349                         {
2350                             xtype: 'Fill',
2351                             xns: Roo.Toolbar
2352                         },
2353                         {
2354                             xtype: 'Button',
2355                             xns: Roo.Toolbar,
2356                             listeners : {
2357                                 click : function ()
2358                                 {
2359                                     var hid = _this.form.findField('pohead_id').getValue();
2360                                 
2361                                     if(!hid.length){
2362                                         Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2363                                         return false;
2364                                     }
2365                                 
2366                                     
2367                                     if (!_this.grid) {
2368                                         _dialog.layout.showPanel(1);
2369                                         doit.defer(500);
2370                                         return;
2371                                     }
2372                                     
2373                                     
2374                                     
2375                                     var doit = function () { 
2376                                         new Pman.Download({
2377                                             grid : _this.grid
2378                                         });
2379                                     }
2380                                     doit();
2381                                             
2382                                    
2383                                 }
2384                             },
2385                             cls : 'x-btn-text-icon',
2386                             text : "Download Purchase Order Items (Excel)",
2387                             icon : rootURL + '/Pman/templates/images/save.gif'
2388                         },
2389                         {
2390                             xtype: 'Button',
2391                             xns: Roo.Toolbar,
2392                             listeners : {
2393                                 render : function (_self)
2394                                 {
2395                                     _this.uploadBtn = _self;
2396                                 }
2397                             },
2398                             text : "Upload Purchase Order",
2399                             menu : {
2400                                 xtype: 'Menu',
2401                                 xns: Roo.menu,
2402                                 items : [
2403                                     {
2404                                         xtype: 'Item',
2405                                         xns: Roo.menu,
2406                                         listeners : {
2407                                             click : function (_self, e)
2408                                             {
2409                                                 var hid = _this.form.findField('pohead_id').getValue();
2410                                                 
2411                                                 if(!hid.length){
2412                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2413                                                     return false;
2414                                                 }
2415                                                 Pman.Dialog.Image.show(
2416                                                    {
2417                                                         timeout : 60000,
2418                                                         _url : baseURL+'/Xtuple/Import/PurchaseOrder?' + Roo.urlEncode({'pohead_id' : hid})
2419                                                     
2420                                                    },
2421                                                    function () {
2422                                                         if(_this.grid){
2423                                                             _this.grid.footer.onClick('first');
2424                                                         }
2425                                                         Roo.MessageBox.alert("Notice", 'UPLOADED');
2426                                                    }
2427                                                );
2428                                             }
2429                                         },
2430                                         text : "Upload Standard Excel"
2431                                     },
2432                                     {
2433                                         xtype: 'Item',
2434                                         xns: Roo.menu,
2435                                         listeners : {
2436                                             click : function (_self, e)
2437                                             {
2438                                             
2439                                                 var hid = _this.form.findField('pohead_id').getValue();
2440                                                 
2441                                                 if(!hid.length){
2442                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2443                                                     return false;
2444                                                 }
2445                                                 
2446                                                Pman.Dialog.Image.show(
2447                                                {
2448                                                     _url : baseURL+'/Xtuple/Import/AUPurchaseOrder?' + Roo.urlEncode({'pohead_id' :hid})
2449                                                     
2450                                                },
2451                                                function (data) {
2452                                                    if(_this.grid){
2453                                                         _this.grid.footer.onClick('first');
2454                                                    }
2455                                                    Roo.MessageBox.alert("Notice", 'IMPORTED');
2456                                             
2457                                                });
2458                                             }
2459                                         },
2460                                         text : "Upload AU Import Excel"
2461                                     }
2462                                 ]
2463                             }
2464                         }
2465                     ]
2466                 }
2467             },
2468             buttons : [
2469                 {
2470                     xtype: 'Button',
2471                     xns: Roo,
2472                     listeners : {
2473                         click : function (_self, e)
2474                         {
2475                             _this.dialog.hide();
2476                         }
2477                     },
2478                     text : "Cancel"
2479                 },
2480                 {
2481                     xtype: 'Button',
2482                     xns: Roo,
2483                     listeners : {
2484                         click : function (_self, e)
2485                         {
2486                             if(_this.grid){
2487                                 var ar = [];
2488                         
2489                                 _this.grid.ds.each(function(r) {
2490                                     ar.push({
2491                                         poitem_id : r.data.poitem_id,
2492                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
2493                                         poitem_unitprice : r.data.poitem_unitprice,
2494                                         poitem_qty_ordered : r.data.poitem_qty_ordered
2495                                     });
2496                                         
2497                                 });
2498                                 
2499                                 _this.form.findField('items').setValue(JSON.stringify(ar));
2500                             }
2501                                 
2502                             _this.form.doAction("submit");
2503                         
2504                         },
2505                         render : function (_self)
2506                         {
2507                             _this.saveBtn = _self;
2508                         }
2509                     },
2510                     text : "Save"
2511                 }
2512             ]
2513         });
2514     }
2515 };