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                                             dataIndex : 'gltrans_amount',
1738                                             header : 'Amount',
1739                                             width : 100,
1740                                             renderer : function(v) { return String.format('{0}', v); }
1741                                         },
1742                                         {
1743                                             xtype: 'ColumnModel',
1744                                             xns: Roo.grid,
1745                                             dataIndex : 'invdetail_qty',
1746                                             header : 'Amount',
1747                                             width : 100,
1748                                             renderer : function(v) { return String.format('{0}', v); }
1749                                         },
1750                                         {
1751                                             xtype: 'ColumnModel',
1752                                             xns: Roo.grid,
1753                                             dataIndex : 'gltrans_notes',
1754                                             header : 'Notes',
1755                                             width : 100,
1756                                             renderer : function(v) { return String.format('{0}', v); }
1757                                         }
1758                                     ]
1759                                 }
1760                             }
1761                         ],
1762                         center : {
1763                             xtype: 'LayoutRegion',
1764                             xns: Roo
1765                         },
1766                         east : {
1767                             xtype: 'LayoutRegion',
1768                             xns: Roo,
1769                             split : true,
1770                             width : 550
1771                         }
1772                     }
1773                 },
1774                 {
1775                     xtype: 'NestedLayoutPanel',
1776                     xns: Roo,
1777                     region : 'center',
1778                     title : "GL Tx",
1779                     layout : {
1780                         xtype: 'BorderLayout',
1781                         xns: Roo,
1782                         items : [
1783                             {
1784                                 xtype: 'GridPanel',
1785                                 xns: Roo,
1786                                 listeners : {
1787                                     activate : function() {
1788                                         _this.gltxpanel = this;
1789                                         if (_this.gltxgrid) {
1790                                             _this.gltxgrid.footer.onClick('first');
1791                                         }
1792                                     }
1793                                 },
1794                                 background : false,
1795                                 fitContainer : true,
1796                                 fitToframe : true,
1797                                 region : 'center',
1798                                 tableName : 'invdetail',
1799                                 title : "invdetail",
1800                                 grid : {
1801                                     xtype: 'Grid',
1802                                     xns: Roo.grid,
1803                                     listeners : {
1804                                         render : function() 
1805                                         {
1806                                             _this.gltxgrid = this; 
1807                                             //_this.dialog = Pman.Dialog.FILL_IN
1808                                             if (_this.gltxpanel.active) {
1809                                                this.footer.onClick('first');
1810                                             }
1811                                         },
1812                                         cellclick : function (_self, rowIndex, columnIndex, e)
1813                                         {
1814                                             if (columnIndex > 0) {
1815                                                 return;
1816                                             }
1817                                             var rec = this.ds.getAt(rowIndex);
1818                                             rec.set('gltrans_as_summary', rec.data.gltrans_as_summary *1 ? 0 : 1);
1819                                             _this.gltxdgrid.footer.onClick('first');
1820                                         }
1821                                     },
1822                                     autoExpandColumn : 'gltrans_accnt_id_accnt_descrip',
1823                                     loadMask : true,
1824                                     sm : {
1825                                         xtype: 'RowSelectionModel',
1826                                         xns: Roo.grid,
1827                                         listeners : {
1828                                             selectionchange : function (_self)
1829                                             {
1830                                                 _this.gltxdgrid.footer.onClick('first');;
1831                                             }
1832                                         },
1833                                         singleSelect : true
1834                                     },
1835                                     dataSource : {
1836                                         xtype: 'Store',
1837                                         xns: Roo.data,
1838                                         listeners : {
1839                                             beforeload : function (_self, o)
1840                                             {
1841                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
1842                                                 if (! o.params.pohead_id ) {
1843                                                     this.removeAll();
1844                                                     return false;
1845                                                 }
1846                                                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
1847                                             }
1848                                         },
1849                                         remoteSort : true,
1850                                         sortInfo : { field : 'item_number', direction: 'ASC' },
1851                                         proxy : {
1852                                             xtype: 'HttpProxy',
1853                                             xns: Roo.data,
1854                                             method : 'GET',
1855                                             url : baseURL + '/Roo/gltrans.php'
1856                                         },
1857                                         reader : {
1858                                             xtype: 'JsonReader',
1859                                             xns: Roo.data,
1860                                             totalProperty : 'total',
1861                                             root : 'data',
1862                                             id : 'id',
1863                                             fields : [
1864                                                 {
1865                                                     'name': 'invdetail_id',
1866                                                     'type': 'int'
1867                                                 },
1868                                                 {
1869                                                     'name': 'invdetail_transtype',
1870                                                     'type': 'string'
1871                                                 },
1872                                                 {
1873                                                     'name': 'invdetail_invhist_id',
1874                                                     'type': 'int'
1875                                                 },
1876                                                 {
1877                                                     'name': 'invdetail_location_id',
1878                                                     'type': 'int'
1879                                                 },
1880                                                 {
1881                                                     'name': 'invdetail_qty',
1882                                                     'type': 'float'
1883                                                 },
1884                                                 {
1885                                                     'name': 'invdetail_comments',
1886                                                     'type': 'string'
1887                                                 },
1888                                                 {
1889                                                     'name': 'invdetail_qty_before',
1890                                                     'type': 'float'
1891                                                 },
1892                                                 {
1893                                                     'name': 'invdetail_qty_after',
1894                                                     'type': 'float'
1895                                                 },
1896                                                 {
1897                                                     'name': 'invdetail_invcitem_id',
1898                                                     'type': 'int'
1899                                                 },
1900                                                 {
1901                                                     'name': 'invdetail_expiration',
1902                                                     'type': 'date',
1903                                                     'dateFormat': 'Y-m-d'
1904                                                 },
1905                                                 {
1906                                                     'name': 'invdetail_warrpurc',
1907                                                     'type': 'date',
1908                                                     'dateFormat': 'Y-m-d'
1909                                                 },
1910                                                 {
1911                                                     'name': 'invdetail_ls_id',
1912                                                     'type': 'int'
1913                                                 }
1914                                             ]
1915                                         }
1916                                     },
1917                                     footer : {
1918                                         xtype: 'PagingToolbar',
1919                                         xns: Roo,
1920                                         displayInfo : true,
1921                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
1922                                         emptyMsg : "No invdetail found",
1923                                         pageSize : 9999,
1924                                         items : [
1925                                             {
1926                                                 xtype: 'Button',
1927                                                 xns: Roo.Toolbar,
1928                                                 listeners : {
1929                                                     render : function (_self)
1930                                                     {
1931                                                         _this.glsalesbtn = _self;
1932                                                     },
1933                                                     click : function (_self, e)
1934                                                     {
1935                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
1936                                                     }
1937                                                 },
1938                                                 enableToggle : true,
1939                                                 pressed : true,
1940                                                 text : "Split sales"
1941                                             }
1942                                         ]
1943                                     },
1944                                     colModel : [
1945                                         {
1946                                             xtype: 'ColumnModel',
1947                                             xns: Roo.grid,
1948                                             dataIndex : 'gltrans_as_summary',
1949                                             header : 'Summary',
1950                                             width : 50,
1951                                             renderer : function(v,x,r) { 
1952                                                 
1953                                                 var state = v*1   ?  '-checked' : '';
1954                                                                                 
1955                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1956                                              }
1957                                         },
1958                                         {
1959                                             xtype: 'ColumnModel',
1960                                             xns: Roo.grid,
1961                                             dataIndex : 'gltrans_accnt_id_accnt_descrip',
1962                                             header : 'Account',
1963                                             width : 75,
1964                                             renderer : function(v) { return String.format('{0}', v); }
1965                                         },
1966                                         {
1967                                             xtype: 'ColumnModel',
1968                                             xns: Roo.grid,
1969                                             align : 'right',
1970                                             dataIndex : 'gltrans_amount_credit',
1971                                             header : 'Credit',
1972                                             width : 75,
1973                                             renderer : function(v) { return String.format('{0}',  Roo.util.Format.number(v,3)); }
1974                                         },
1975                                         {
1976                                             xtype: 'ColumnModel',
1977                                             xns: Roo.grid,
1978                                             align : 'right',
1979                                             dataIndex : 'gltrans_amount_debit',
1980                                             header : 'Debit',
1981                                             width : 75,
1982                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
1983                                         },
1984                                         {
1985                                             xtype: 'ColumnModel',
1986                                             xns: Roo.grid,
1987                                             align : 'right',
1988                                             dataIndex : 'gltrans_amount_total',
1989                                             header : 'Sum',
1990                                             width : 75,
1991                                             renderer : function(v) { return String.format('<b>{0}</b>', Roo.util.Format.number(v,3)); }
1992                                         },
1993                                         {
1994                                             xtype: 'ColumnModel',
1995                                             xns: Roo.grid,
1996                                             align : 'right',
1997                                             dataIndex : 'gltrans_amount_total_unposted',
1998                                             header : 'Unposted',
1999                                             width : 75,
2000                                             renderer : function(v) { return String.format('<span style="color:red">{0}</span>', Roo.util.Format.number(v,3)); }
2001                                         }
2002                                     ]
2003                                 }
2004                             },
2005                             {
2006                                 xtype: 'GridPanel',
2007                                 xns: Roo,
2008                                 listeners : {
2009                                     activate : function() {
2010                                         _this.gltxdpanel = this;
2011                                         if (_this.gltxdgrid) {
2012                                             _this.gltxdgrid.footer.onClick('first');
2013                                         }
2014                                     }
2015                                 },
2016                                 background : false,
2017                                 fitContainer : true,
2018                                 fitToframe : true,
2019                                 region : 'east',
2020                                 tableName : 'invdetail',
2021                                 title : "invdetail",
2022                                 grid : {
2023                                     xtype: 'Grid',
2024                                     xns: Roo.grid,
2025                                     listeners : {
2026                                         render : function() 
2027                                         {
2028                                             _this.gltxdgrid = this; 
2029                                             //_this.dialog = Pman.Dialog.FILL_IN
2030                                             if (_this.gltxdpanel.active) {
2031                                                this.footer.onClick('first');
2032                                             }
2033                                         },
2034                                         cellclick : function (_self, ri, ci, e)
2035                                         {
2036                                             
2037                                               var deleteSel = function() {
2038                                             
2039                                                 new Pman.Request({
2040                                                     mask : "Reversing",
2041                                                     url : baseURL + '/Roo/gltrans',
2042                                                     method : 'POST',
2043                                                     params : {  
2044                                                         _void : 1,
2045                                                         gltrans_id : rec.data.gltrans_id
2046                                                         
2047                                                     }, 
2048                                                     success : function() {
2049                                                         rec.set('gltrans_posted', false);
2050                                                         rec.set('gltrans_deleted', true);
2051                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2052                                                        _this.gltxgrid.footer.onClick('first');
2053                                                     }
2054                                                 });
2055                                             
2056                                             }
2057                                             var undeleteSel = function() {
2058                                             
2059                                                 new Pman.Request({
2060                                                     mask : "Reversing",
2061                                                     url : baseURL + '/Roo/gltrans',
2062                                                     method : 'POST',
2063                                                     params : {  
2064                                                         _unvoid : 1,
2065                                                         gltrans_id : rec.data.gltrans_id
2066                                                         
2067                                                     }, 
2068                                                     success : function() {
2069                                                         rec.set('gltrans_posted', true);
2070                                                         rec.set('gltrans_deleted', false);
2071                                                         rec.set('gltrans_docnumber', rec.data.gltrans_docnumber);
2072                                                        _this.gltxgrid.footer.onClick('first');
2073                                                     }
2074                                                 });
2075                                             
2076                                             }
2077                                             
2078                                             var di = this.colModel.config[ci].dataIndex;
2079                                             if (di != 'gltrans_posted') {
2080                                                 return;
2081                                             }
2082                                             
2083                                             
2084                                             
2085                                             var rec = this.ds.getAt(ri);
2086                                             if (rec.data.gltrans_deleted) {
2087                                             
2088                                                  Roo.MessageBox.confirm(
2089                                                     "Confirm", 
2090                                                     "This should only be used by System Administrators - are you sure you know what you are doing!",
2091                                                     function(x) {
2092                                                         if (x != 'yes') {
2093                                                             return;
2094                                                         }
2095                                                         undeleteSel();
2096                                                     }
2097                                                 );
2098                                             
2099                                                 return false;
2100                                             }
2101                                         
2102                                             
2103                                             
2104                                             if (!rec.data.gltrans_posted) {
2105                                         
2106                                                 
2107                                                 
2108                                                 new Pman.Request({
2109                                                     method : 'POST',
2110                                                     url : baseURL + '/Roo/gltrans',
2111                                                     mask : "Posting",
2112                                                     params : {
2113                                                         _post : 1,
2114                                                         gltrans_id : rec.data.gltrans_id
2115                                                     },
2116                                                     success : function (res)
2117                                                     {
2118                                                         rec.set('gltrans_posted', true);
2119                                                         _this.gltxgrid.footer.onClick('first');
2120                                                     
2121                                                     }
2122                                                 
2123                                                 
2124                                                 });
2125                                                 return;
2126                                             }
2127                                             
2128                                             // we have a posted transaction.
2129                                             // only allow recalled to be deleted..
2130                                             if (!rec.data.gltrans_notes.match(/(Recall|Ship Order)/)) {
2131                                                 return false;
2132                                             }
2133                                             
2134                                             
2135                                          
2136                                             
2137                                             
2138                                         
2139                                             Roo.MessageBox.confirm(
2140                                                 "Confirm", 
2141                                                 "This should only be used by System Administrators - are you sure you know what you are doing!",
2142                                                 function(x) {
2143                                                     if (x != 'yes') {
2144                                                         return;
2145                                                     }
2146                                                     deleteSel();
2147                                                 }
2148                                             );
2149                                                   
2150                                             
2151                                             
2152                                         }
2153                                     },
2154                                     autoExpandColumn : 'gltrans_notes',
2155                                     loadMask : true,
2156                                     dataSource : {
2157                                         xtype: 'Store',
2158                                         xns: Roo.data,
2159                                         listeners : {
2160                                             beforeload : function (_self, o)
2161                                             {
2162                                                 o.params.pohead_id = _this.form.findField('pohead_id').getValue();
2163                                                 var s = _this.gltxgrid.selModel.getSelected();
2164                                                 if (!s) { 
2165                                                     this.removeAll();
2166                                                     return false;
2167                                                 }
2168                                                 o.params.gltrans_accnt_id = s.data.gltrans_accnt_id;
2169                                                 o.params.gltrans_is_ship = s.data.gltrans_is_ship;
2170                                                 o.params.gltrans_as_summary =     s.data.gltrans_as_summary;
2171                                                  o.params._hide_void = _this.glvoidshow.pressed ? 1 : 0;
2172                                                 //glvoidshow
2173                                                 
2174                                             }
2175                                         },
2176                                         remoteSort : true,
2177                                         sortInfo : { field : 'gltrans_docnumber', direction: 'ASC' },
2178                                         proxy : {
2179                                             xtype: 'HttpProxy',
2180                                             xns: Roo.data,
2181                                             method : 'GET',
2182                                             url : baseURL + '/Roo/gltrans.php'
2183                                         },
2184                                         reader : {
2185                                             xtype: 'JsonReader',
2186                                             xns: Roo.data,
2187                                             totalProperty : 'total',
2188                                             root : 'data',
2189                                             id : 'id',
2190                                             fields : [
2191                                                 {
2192                                                     'name': 'invdetail_id',
2193                                                     'type': 'int'
2194                                                 },
2195                                                 {
2196                                                     'name': 'invdetail_transtype',
2197                                                     'type': 'string'
2198                                                 },
2199                                                 {
2200                                                     'name': 'invdetail_invhist_id',
2201                                                     'type': 'int'
2202                                                 },
2203                                                 {
2204                                                     'name': 'invdetail_location_id',
2205                                                     'type': 'int'
2206                                                 },
2207                                                 {
2208                                                     'name': 'invdetail_qty',
2209                                                     'type': 'float'
2210                                                 },
2211                                                 {
2212                                                     'name': 'invdetail_comments',
2213                                                     'type': 'string'
2214                                                 },
2215                                                 {
2216                                                     'name': 'invdetail_qty_before',
2217                                                     'type': 'float'
2218                                                 },
2219                                                 {
2220                                                     'name': 'invdetail_qty_after',
2221                                                     'type': 'float'
2222                                                 },
2223                                                 {
2224                                                     'name': 'invdetail_invcitem_id',
2225                                                     'type': 'int'
2226                                                 },
2227                                                 {
2228                                                     'name': 'invdetail_expiration',
2229                                                     'type': 'date',
2230                                                     'dateFormat': 'Y-m-d'
2231                                                 },
2232                                                 {
2233                                                     'name': 'invdetail_warrpurc',
2234                                                     'type': 'date',
2235                                                     'dateFormat': 'Y-m-d'
2236                                                 },
2237                                                 {
2238                                                     'name': 'invdetail_ls_id',
2239                                                     'type': 'int'
2240                                                 }
2241                                             ]
2242                                         }
2243                                     },
2244                                     footer : {
2245                                         xtype: 'PagingToolbar',
2246                                         xns: Roo,
2247                                         displayInfo : true,
2248                                         displayMsg : "Displaying invdetail{0} - {1} of {2}",
2249                                         emptyMsg : "No invdetail found",
2250                                         pageSize : 9999,
2251                                         items : [
2252                                             {
2253                                                 xtype: 'Button',
2254                                                 xns: Roo.Toolbar,
2255                                                 listeners : {
2256                                                     click : function (_self, e)
2257                                                     {
2258                                                         new Pman.Download( {
2259                                                             grid : _this.gltxdgrid
2260                                                         
2261                                                         });
2262                                                     }
2263                                                 },
2264                                                 text : "Download"
2265                                             },
2266                                             {
2267                                                 xtype: 'Button',
2268                                                 xns: Roo.Toolbar,
2269                                                 listeners : {
2270                                                     render : function (_self)
2271                                                     {
2272                                                         _this.glvoidshow = _self;
2273                                                     },
2274                                                     click : function (_self, e)
2275                                                     {
2276                                                         (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
2277                                                     }
2278                                                 },
2279                                                 enableToggle : true,
2280                                                 pressed : true,
2281                                                 text : "Hide Void"
2282                                             }
2283                                         ]
2284                                     },
2285                                     colModel : [
2286                                         {
2287                                             xtype: 'ColumnModel',
2288                                             xns: Roo.grid,
2289                                             dataIndex : 'gltrans_id',
2290                                             header : 'Ref#',
2291                                             sortable : true,
2292                                             width : 75,
2293                                             renderer : function(v) { return String.format('{0}', v ); }
2294                                         },
2295                                         {
2296                                             xtype: 'ColumnModel',
2297                                             xns: Roo.grid,
2298                                             dataIndex : 'gltrans_date',
2299                                             header : 'Date',
2300                                             width : 75,
2301                                             renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
2302                                         },
2303                                         {
2304                                             xtype: 'ColumnModel',
2305                                             xns: Roo.grid,
2306                                             dataIndex : 'gltrans_docnumber',
2307                                             header : 'Doc#',
2308                                             width : 75,
2309                                             renderer : function(v,x,r) { 
2310                                                 if (r.data.gltrans_deleted) {
2311                                                    return String.format('<s>{0}</s>', v);     
2312                                                 }
2313                                                 return String.format('{0}', v); 
2314                                             }
2315                                         },
2316                                         {
2317                                             xtype: 'ColumnModel',
2318                                             xns: Roo.grid,
2319                                             dataIndex : 'gltrans_source',
2320                                             header : 'Source',
2321                                             width : 50,
2322                                             renderer : function(v) { return String.format('{0}', v); }
2323                                         },
2324                                         {
2325                                             xtype: 'ColumnModel',
2326                                             xns: Roo.grid,
2327                                             dataIndex : 'gltrans_notes',
2328                                             header : 'Notes',
2329                                             width : 75,
2330                                             renderer : function(v) { return String.format('{0}', v); }
2331                                         },
2332                                         {
2333                                             xtype: 'ColumnModel',
2334                                             xns: Roo.grid,
2335                                             align : 'right',
2336                                             dataIndex : 'gltrans_amount',
2337                                             header : 'Amount',
2338                                             width : 75,
2339                                             renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v,3)); }
2340                                         },
2341                                         {
2342                                             xtype: 'ColumnModel',
2343                                             xns: Roo.grid,
2344                                             dataIndex : 'gltrans_posted',
2345                                             header : 'Posted',
2346                                             width : 50,
2347                                             renderer : function(v,x,r) { 
2348                                                 
2349                                                 var state = v   ?  '-checked' : '';
2350                                                                                 
2351                                                 return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
2352                                              }
2353                                         }
2354                                     ]
2355                                 }
2356                             }
2357                         ],
2358                         center : {
2359                             xtype: 'LayoutRegion',
2360                             xns: Roo
2361                         },
2362                         east : {
2363                             xtype: 'LayoutRegion',
2364                             xns: Roo,
2365                             split : true,
2366                             width : 500
2367                         }
2368                     }
2369                 }
2370             ],
2371             center : {
2372                 xtype: 'LayoutRegion',
2373                 xns: Roo,
2374                 alwaysShowTabs : true,
2375                 tabPosition : 'top',
2376                 toolbar : {
2377                     xtype: 'Toolbar',
2378                     xns: Roo,
2379                     items : [
2380                         {
2381                             xtype: 'Fill',
2382                             xns: Roo.Toolbar
2383                         },
2384                         {
2385                             xtype: 'Button',
2386                             xns: Roo.Toolbar,
2387                             listeners : {
2388                                 click : function ()
2389                                 {
2390                                     var hid = _this.form.findField('pohead_id').getValue();
2391                                 
2392                                     if(!hid.length){
2393                                         Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2394                                         return false;
2395                                     }
2396                                 
2397                                     
2398                                     if (!_this.grid) {
2399                                         _dialog.layout.showPanel(1);
2400                                         doit.defer(500);
2401                                         return;
2402                                     }
2403                                     
2404                                     
2405                                     
2406                                     var doit = function () { 
2407                                         new Pman.Download({
2408                                             grid : _this.grid
2409                                         });
2410                                     }
2411                                     doit();
2412                                             
2413                                    
2414                                 }
2415                             },
2416                             cls : 'x-btn-text-icon',
2417                             text : "Download Purchase Order Items (Excel)",
2418                             icon : rootURL + '/Pman/templates/images/save.gif'
2419                         },
2420                         {
2421                             xtype: 'Button',
2422                             xns: Roo.Toolbar,
2423                             listeners : {
2424                                 render : function (_self)
2425                                 {
2426                                     _this.uploadBtn = _self;
2427                                 }
2428                             },
2429                             text : "Upload Purchase Order",
2430                             menu : {
2431                                 xtype: 'Menu',
2432                                 xns: Roo.menu,
2433                                 items : [
2434                                     {
2435                                         xtype: 'Item',
2436                                         xns: Roo.menu,
2437                                         listeners : {
2438                                             click : function (_self, e)
2439                                             {
2440                                                 var hid = _this.form.findField('pohead_id').getValue();
2441                                                 
2442                                                 if(!hid.length){
2443                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2444                                                     return false;
2445                                                 }
2446                                                 Pman.Dialog.Image.show(
2447                                                    {
2448                                                         timeout : 60000,
2449                                                         _url : baseURL+'/Xtuple/Import/PurchaseOrder?' + Roo.urlEncode({'pohead_id' : hid})
2450                                                     
2451                                                    },
2452                                                    function () {
2453                                                         if(_this.grid){
2454                                                             _this.grid.footer.onClick('first');
2455                                                         }
2456                                                         Roo.MessageBox.alert("Notice", 'UPLOADED');
2457                                                    }
2458                                                );
2459                                             }
2460                                         },
2461                                         text : "Upload Standard Excel"
2462                                     },
2463                                     {
2464                                         xtype: 'Item',
2465                                         xns: Roo.menu,
2466                                         listeners : {
2467                                             click : function (_self, e)
2468                                             {
2469                                             
2470                                                 var hid = _this.form.findField('pohead_id').getValue();
2471                                                 
2472                                                 if(!hid.length){
2473                                                     Roo.MessageBox.alert("Error", "Please save your purchase order first"); 
2474                                                     return false;
2475                                                 }
2476                                                 
2477                                                Pman.Dialog.Image.show(
2478                                                {
2479                                                     _url : baseURL+'/Xtuple/Import/AUPurchaseOrder?' + Roo.urlEncode({'pohead_id' :hid})
2480                                                     
2481                                                },
2482                                                function (data) {
2483                                                    if(_this.grid){
2484                                                         _this.grid.footer.onClick('first');
2485                                                    }
2486                                                    Roo.MessageBox.alert("Notice", 'IMPORTED');
2487                                             
2488                                                });
2489                                             }
2490                                         },
2491                                         text : "Upload AU Import Excel"
2492                                     }
2493                                 ]
2494                             }
2495                         }
2496                     ]
2497                 }
2498             },
2499             buttons : [
2500                 {
2501                     xtype: 'Button',
2502                     xns: Roo,
2503                     listeners : {
2504                         click : function (_self, e)
2505                         {
2506                             _this.dialog.hide();
2507                         }
2508                     },
2509                     text : "Cancel"
2510                 },
2511                 {
2512                     xtype: 'Button',
2513                     xns: Roo,
2514                     listeners : {
2515                         click : function (_self, e)
2516                         {
2517                             if(_this.grid){
2518                                 var ar = [];
2519                         
2520                                 _this.grid.ds.each(function(r) {
2521                                     ar.push({
2522                                         poitem_id : r.data.poitem_id,
2523                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
2524                                         poitem_unitprice : r.data.poitem_unitprice,
2525                                         poitem_qty_ordered : r.data.poitem_qty_ordered
2526                                     });
2527                                         
2528                                 });
2529                                 
2530                                 _this.form.findField('items').setValue(JSON.stringify(ar));
2531                             }
2532                                 
2533                             _this.form.doAction("submit");
2534                         
2535                         },
2536                         render : function (_self)
2537                         {
2538                             _this.saveBtn = _self;
2539                         }
2540                     },
2541                     text : "Save"
2542                 }
2543             ]
2544         });
2545     }
2546 };