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