Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtupleExpenses.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.XtupleExpenses = {
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             closable : false,
34             collapsible : false,
35             height : 640,
36             modal : true,
37             resizable : false,
38             title : "Edit / Create expense Report",
39             width : 900,
40             items : [
41                 {
42                     xtype: 'ContentPanel',
43                     xns: Roo,
44                     region : 'north',
45                     items : [
46                         {
47                             xtype: 'Form',
48                             xns: Roo.form,
49                             listeners : {
50                                 actioncomplete : function(_self,action)
51                                 {
52                                     
53                                     var btns = ['postToManagement', 'postToAccounts','postToGL', 'postToStaff', 'saveBtn'];
54                                     var  showhide = function()
55                                     {
56                                         Roo.each(btns, function(b) {
57                                             _this[b].hide();
58                                         });
59                                         switch(_this.form.findField('expense_status').getValue()) {
60                                             case '':
61                                                 _this['saveBtn'].show();
62                                                 return; // do not show any button...
63                                             case 'Draft':            
64                                                 _this['saveBtn'].show();
65                                                 _this['postToManagement'].show();
66                                                 break;
67                                                 
68                                                 
69                                             case 'Pending Management Approval':
70                                             case 'Pending Supervisor Approval': // old system..
71                                                 // check if they are managmenet..
72                                                 // eg. have to be in TIER2
73                                                 if (!Pman.Login.inGroup('TIER2') && !Pman.Login.inGroup('TIER1') && 
74                                                          !Pman.Login.inGroup('Administrators')) {
75                                                     return;
76                                                 }
77                                                 _this['postToAccounts'].show();
78                                                 _this['postToStaff'].show(); 
79                                                 _this['saveBtn'].show();
80                                                 break;
81                                             case 'Pending Accounting Approval':
82                                                 if (!Pman.Login.inGroup('Administrators')) {
83                                                     return;
84                                                 }
85                                             
86                                                 // check if they are managmenet..
87                                                 _this['postToGL'].show();
88                                                 _this['postToStaff'].show();                
89                                                 _this['saveBtn'].show();                
90                                                 break;
91                                             
92                                         
93                                         }
94                                     }
95                                     
96                                     if (action.type == 'setdata') {
97                                        //_this.dialog.el.mask("Loading");
98                                        if (_this.data.expense_id) {
99                                            this.load({ method: 'GET', params: { '_id' : _this.data.expense_id }});
100                                              
101                                            return;
102                                        }
103                                        showhide();
104                                        _this.grid.ds.load({});
105                                        return;
106                                     }
107                                     if (action.type == 'load') {
108                                     
109                                     
110                                         showhide();
111                                     
112                                     
113                                     
114                                        _this.grid.ds.load({});
115                                         return;
116                                     }
117                                     if (action.type =='submit') {
118                                         
119                                         
120                                         if (! (1 * _this.form.findField('expense_id').getValue()) ) {
121                                             Roo.log("fire event");
122                                             _this.data = action.result.data;
123                                             this.fireEvent('actioncomplete', this,  { type: 'setdata', data: action.result.data });
124                                             return;
125                                         }
126                                         
127                                  
128                                         _this.dialog.hide();
129                                     
130                                          if (_this.callback) {
131                                             _this.callback.call(_this, _this.form.getValues());
132                                          }
133                                          _this.form.reset();
134                                          return;
135                                     }
136                                 },
137                                 rendered : function (form)
138                                 {
139                                     _this.form= form;
140                                 }
141                             },
142                             method : 'POST',
143                             style : 'margin:10px;',
144                             url : baseURL + '/Roo/expense.php',
145                             items : [
146                                 {
147                                     xtype: 'Column',
148                                     xns: Roo.form,
149                                     width : 400,
150                                     items : [
151                                         {
152                                             xtype: 'FieldSet',
153                                             xns: Roo.form,
154                                             legend : "Summary",
155                                             style : 'width:380px',
156                                             items : [
157                                                 {
158                                                     xtype: 'TextField',
159                                                     xns: Roo.form,
160                                                     fieldLabel : 'Ref#',
161                                                     name : 'expense_number',
162                                                     readOnly : true,
163                                                     width : 200
164                                                 },
165                                                 {
166                                                     xtype: 'DateField',
167                                                     xns: Roo.form,
168                                                     fieldLabel : 'Due Date',
169                                                     format : 'Y-m-d',
170                                                     name : 'expense_trandate',
171                                                     width : 100
172                                                 },
173                                                 {
174                                                     xtype: 'TextField',
175                                                     xns: Roo.form,
176                                                     fieldLabel : 'Summary',
177                                                     name : 'expense_memo',
178                                                     width : 200
179                                                 },
180                                                 {
181                                                     xtype: 'TextField',
182                                                     xns: Roo.form,
183                                                     fieldLabel : 'Status',
184                                                     name : 'expense_status',
185                                                     readOnly : true,
186                                                     width : 200
187                                                 }
188                                             ]
189                                         },
190                                         {
191                                             xtype: 'Row',
192                                             xns: Roo.form,
193                                             labelAlign : 'top',
194                                             style : 'clear:both;float:left;',
195                                             items : [
196                                                 {
197                                                     xtype: 'TextArea',
198                                                     xns: Roo.form,
199                                                     fieldLabel : 'Comments / For Review etc.',
200                                                     name : 'expense_comments',
201                                                     width : 400
202                                                 }
203                                             ]
204                                         }
205                                     ]
206                                 },
207                                 {
208                                     xtype: 'Column',
209                                     xns: Roo.form,
210                                     width : 400,
211                                     items : [
212                                         {
213                                             xtype: 'FieldSet',
214                                             xns: Roo.form,
215                                             labelWidth : 50,
216                                             legend : "Employee",
217                                             style : 'width:250px;margin-left:10px',
218                                             items : [
219                                                 {
220                                                     xtype: 'TextField',
221                                                     xns: Roo.form,
222                                                     fieldLabel : 'Name',
223                                                     name : 'expense_emp_id_emp_name',
224                                                     readOnly : true
225                                                 }
226                                             ]
227                                         },
228                                         {
229                                             xtype: 'FieldSet',
230                                             xns: Roo.form,
231                                             legend : "Financial Details",
232                                             style : 'width:250px;margin-left:10px',
233                                             items : [
234                                                 {
235                                                     xtype: 'TextField',
236                                                     xns: Roo.form,
237                                                     fieldLabel : 'Advance Paid',
238                                                     name : 'expense_advance',
239                                                     width : 75
240                                                 },
241                                                 {
242                                                     xtype: 'TextField',
243                                                     xns: Roo.form,
244                                                     fieldLabel : 'Amount',
245                                                     name : 'expense_amount_ro',
246                                                     readOnly : true,
247                                                     width : 75
248                                                 },
249                                                 {
250                                                     xtype: 'TextField',
251                                                     xns: Roo.form,
252                                                     fieldLabel : 'Tax',
253                                                     name : 'expense_tax_ro',
254                                                     readOnly : true,
255                                                     width : 75
256                                                 },
257                                                 {
258                                                     xtype: 'TextField',
259                                                     xns: Roo.form,
260                                                     fieldLabel : 'Total',
261                                                     name : 'expense_total_ro',
262                                                     readOnly : true,
263                                                     width : 75
264                                                 },
265                                                 {
266                                                     xtype: 'Row',
267                                                     xns: Roo.form,
268                                                     labelAlign : 'top',
269                                                     items : [
270                                                         {
271                                                             xtype: 'ComboBox',
272                                                             xns: Roo.form,
273                                                             allowBlank : true,
274                                                             displayField : 'accnt_descrip',
275                                                             editable : false,
276                                                             emptyText : "Select accnt",
277                                                             fieldLabel : 'Paid from Bank Account (accounting only)',
278                                                             forceSelection : true,
279                                                             hiddenName : 'expense_accnt_id',
280                                                             listWidth : 400,
281                                                             loadingText : "Searching...",
282                                                             minChars : 2,
283                                                             name : 'expense_accnt_id_accnt_descrip',
284                                                             pageSize : 20,
285                                                             qtip : "Select accnt",
286                                                             queryParam : '',
287                                                             selectOnFocus : true,
288                                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{accnt_descrip}</b> </div>',
289                                                             triggerAction : 'all',
290                                                             valueField : 'accnt_id',
291                                                             width : 250,
292                                                             store : {
293                                                                 xtype: 'Store',
294                                                                 xns: Roo.data,
295                                                                 listeners : {
296                                                                     beforeload : function (_self, o){
297                                                                         o.params = o.params || {};
298                                                                         // set more here
299                                                                         o.params.accnt_subaccnttype_code =  'CA';
300                                                                     }
301                                                                 },
302                                                                 remoteSort : true,
303                                                                 sortInfo : { direction : 'ASC', field: 'accnt_descrip' },
304                                                                 proxy : {
305                                                                     xtype: 'HttpProxy',
306                                                                     xns: Roo.data,
307                                                                     method : 'GET',
308                                                                     url : baseURL + '/Roo/accnt.php'
309                                                                 },
310                                                                 reader : {
311                                                                     xtype: 'JsonReader',
312                                                                     xns: Roo.data,
313                                                                     id : 'id',
314                                                                     root : 'data',
315                                                                     totalProperty : 'total',
316                                                                     fields : [{"name":"id","type":"int"},{"name":"accnt_number","type":"string"}]
317                                                                 }
318                                                             }
319                                                         }
320                                                     ]
321                                                 }
322                                             ]
323                                         }
324                                     ]
325                                 },
326                                 {
327                                     xtype: 'Hidden',
328                                     xns: Roo.form,
329                                     name : 'base_curr_id'
330                                 },
331                                 {
332                                     xtype: 'Hidden',
333                                     xns: Roo.form,
334                                     name : 'base_curr_name'
335                                 },
336                                 {
337                                     xtype: 'Hidden',
338                                     xns: Roo.form,
339                                     name : 'def_expcat_id'
340                                 },
341                                 {
342                                     xtype: 'Hidden',
343                                     xns: Roo.form,
344                                     name : 'def_expcat_descrip'
345                                 },
346                                 {
347                                     xtype: 'Hidden',
348                                     xns: Roo.form,
349                                     name : 'expense_emp_id'
350                                 },
351                                 {
352                                     xtype: 'Hidden',
353                                     xns: Roo.form,
354                                     name : 'expense_id'
355                                 },
356                                 {
357                                     xtype: 'Hidden',
358                                     xns: Roo.form,
359                                     name : '_post'
360                                 }
361                             ]
362                         }
363                     ]
364                 },
365                 {
366                     xtype: 'GridPanel',
367                     xns: Roo,
368                     listeners : {
369                         activate : function() {
370                             _this.panel = this;
371                             if (_this.grid) {
372                               //  _this.grid.footer.onClick('first');
373                             }
374                         }
375                     },
376                     background : false,
377                     fitContainer : true,
378                     fitToframe : true,
379                     region : 'center',
380                     tableName : 'expitem',
381                     title : "expitem",
382                     grid : {
383                         xtype: 'EditorGrid',
384                         xns: Roo.grid,
385                         listeners : {
386                             render : function() 
387                             {
388                                 _this.grid = this; 
389                                 //_this.dialog = Pman.Dialog.FILL_IN
390                                 if (_this.panel.active) {
391                                    //this.gi.onClick('first');
392                                 }
393                             },
394                             rowdblclick : function (_self, rowIndex, e)
395                             {
396                                 if (!_this.dialog) return;
397                                 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
398                                     _this.grid.footer.onClick('first');
399                                 }); 
400                             },
401                             afteredit : function (e)
402                             {
403                                 
404                                 if (e.field == 'expitem_date') {
405                                     e.record.set('expitem_date', Date.parseDate(e.value, 'Y-m-d'));
406                                 
407                                 } 
408                                 
409                                 e.record.commit();
410                             }
411                         },
412                         autoExpandColumn : 'expitem_memo',
413                         clicksToEdit : 1,
414                         loadMask : true,
415                         dataSource : {
416                             xtype: 'Store',
417                             xns: Roo.data,
418                             listeners : {
419                                 beforeload : function (_self, options)
420                                 {
421                                     
422                                     options.params = options.param || {};
423                                     options.params.limit = 999;
424                                     _this.grid.view.el.unmask();
425                                     options.params.expitem_expense_id = _this.form.findField('expense_id').getValue() *1 ;
426                                    if (!    options.params.expitem_expense_id) {
427                                          Roo.log("no expense id yet");
428                                         this.removeAll();
429                                         _this.grid.view.el.mask("Save First");
430                                         return false;
431                                     }
432                                     
433                                 },
434                                 update : function (_self, record, operation)
435                                 {
436                                     if (operation != 'commit') {
437                                         return;
438                                     }
439                                     var send = Roo.apply({}, record.data);
440                                     // fix date...
441                                     send.expitem_date = typeof(send.expitem_date) == 'object' ? send.expitem_date.format('Y-m-d') : send.expitem_date;
442                                     
443                                     
444                                     function updateTotals(){
445                                         var t = { expense_total_ro : 0 , expense_amount_ro : 0, expense_tax_ro : 0 }
446                                         _this.grid.ds.each(function(r) {
447                                             var fc_total = (r.data.expitem_tax * 1) + (r.data.expitem_amount_fc * 1);
448                                             if (!fc_total) {
449                                                 return;
450                                             }
451                                             var base_total = r.data.expitem_total * 1;
452                                             var rate = base_total / fc_total;
453                                             t.expense_total_ro += base_total;
454                                             t.expense_amount_ro += (r.data.expitem_amount_fc * rate);
455                                             t.expense_tax_ro += (r.data.expitem_tax  * rate);
456                                         
457                                         });
458                                         t.expense_total_ro =         t.expense_total_ro.toFixed(2);
459                                         t.expense_amount_ro =        t.expense_amount_ro.toFixed(2);
460                                         t.expense_tax_ro = t.expense_tax_ro.toFixed(2);
461                                     
462                                         
463                                         _this.form.setValues(t);
464                                     }
465                                     
466                                     
467                                     new Pman.Request( {
468                                         method : 'POST' ,
469                                         url : baseURL + '/Roo/expitem',
470                                         params :send,
471                                         success : function(res) {
472                                            if (!record.data.expitem_id) {
473                                                 record.set('expitem_id', res.data.expitem_id);
474                                            }
475                                            record.set('expitem_total', res.data.expitem_total);
476                                            updateTotals();
477                                         }
478                                     });
479                                     
480                                     
481                                     
482                                 }
483                             },
484                             remoteSort : true,
485                             sortInfo : { field : 'expitem_row', direction: 'ASC' },
486                             proxy : {
487                                 xtype: 'HttpProxy',
488                                 xns: Roo.data,
489                                 method : 'GET',
490                                 url : baseURL + '/Roo/expitem.php'
491                             },
492                             reader : {
493                                 xtype: 'JsonReader',
494                                 xns: Roo.data,
495                                 totalProperty : 'total',
496                                 root : 'data',
497                                 id : 'id',
498                                 fields : [
499                                     {
500                                         'name': 'expitem_id',
501                                         'type': 'int'
502                                     },
503                                     {
504                                         'name': 'expitem_expense_id',
505                                         'type': 'int'
506                                     },
507                                     {
508                                         'name': 'expitem_curr_id',
509                                         'type': 'int'
510                                     },
511                                     {
512                                         'name': 'expitem_expcat_id',
513                                         'type': 'int'
514                                     },
515                                     {
516                                         'name': 'expitem_row',
517                                         'type': 'int'
518                                     },
519                                     {
520                                         'name': 'expitem_amount',
521                                         'type': 'float'
522                                     },
523                                     {
524                                         'name': 'expitem_amount_fc',
525                                         'type': 'float'
526                                     },
527                                     {
528                                         'name': 'expitem_tax',
529                                         'type': 'float'
530                                     },
531                                     {
532                                         'name': 'expitem_total',
533                                         'type': 'float'
534                                     },
535                                     {
536                                         'name': 'expitem_date',
537                                         'type': 'date',
538                                         'dateFormat': 'Y-m-d'
539                                     },
540                                     {
541                                         'name': 'expitem_is_billable',
542                                         'type': 'int'
543                                     },
544                                     {
545                                         'name': 'expitem_memo',
546                                         'type': 'string'
547                                     }
548                                 ]
549                             }
550                         },
551                         toolbar : {
552                             xtype: 'Toolbar',
553                             xns: Roo,
554                             items : [
555                                 {
556                                     xtype: 'Button',
557                                     xns: Roo.Toolbar,
558                                     listeners : {
559                                         click : function()
560                                         {
561                                            
562                                            
563                                          
564                                            var grid = _this.grid;
565                                            var r = grid.getDataSource().reader.newRow({
566                                                 expitem_id : 0,
567                                                 expitem_expense_id : _this.form.findField('expense_id').getValue(),
568                                                 expitem_row : grid.ds.getCount() + 1,
569                                                 expitem_date : new Date(),
570                                                 expitem_curr_id :           _this.form.findField('base_curr_id').getValue(),
571                                                 expitem_curr_id_curr_name : _this.form.findField('base_curr_name').getValue(),
572                                                 expitem_expcat_id :         _this.form.findField('def_expcat_id').getValue(),
573                                                 expitem_expcat_id_expcat_descrip  : _this.form.findField('def_expcat_descrip').getValue(),
574                                                 expitem_amount_tax : 0.0
575                                            
576                                            });
577                                                
578                                             grid.stopEditing();
579                                             var lr =   grid.ds.getCount()
580                                             grid.getDataSource().insert(lr, r); 
581                                             grid.startEditing(lr, 1); 
582                                         }
583                                     },
584                                     cls : 'x-btn-text-icon',
585                                     text : "Add",
586                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
587                                 },
588                                 {
589                                     xtype: 'Fill',
590                                     xns: Roo.Toolbar
591                                 },
592                                 {
593                                     xtype: 'Button',
594                                     xns: Roo.Toolbar,
595                                     listeners : {
596                                         click : function()
597                                         {
598                                             var ce =  _this.grid.selModel.getSelectedCell();
599                                             if (!ce) {
600                                                 Roo.MessageBox.alert("Error", "Select a line to delete");
601                                                 return;
602                                             }
603                                             var rec = _this.grid.ds.getAt(ce[0]);
604                                             if (!rec.data.expitem_id) {
605                                                 _this.grid.ds.remove(rec);
606                                                 return;
607                                             }
608                                             
609                                             
610                                             new Pman.Request({
611                                                 mask : 'Deleting',
612                                                 url : baseURL + '/Roo/expitem',
613                                                 method : 'POST',
614                                                 params : {
615                                                     _delete : rec.data.expitem_id
616                                                 },
617                                                 success : function()
618                                                 {
619                                                     _this.grid.ds.remove(rec);            
620                                                 }
621                                             });
622                                            
623                                            
624                                         }
625                                     },
626                                     cls : 'x-btn-text-icon',
627                                     text : "Delete",
628                                     icon : rootURL + '/Pman/templates/images/trash.gif'
629                                 }
630                             ]
631                         },
632                         colModel : [
633                             {
634                                 xtype: 'ColumnModel',
635                                 xns: Roo.grid,
636                                 dataIndex : 'expitem_row',
637                                 header : 'Line#',
638                                 width : 50,
639                                 renderer : function(v) { return String.format('{0}', v); }
640                             },
641                             {
642                                 xtype: 'ColumnModel',
643                                 xns: Roo.grid,
644                                 dataIndex : 'expitem_date',
645                                 header : 'Date',
646                                 width : 75,
647                                 renderer : function(v) {
648                                     if (!v) {
649                                         return '<span style="color:red">' + "NO DATE" + '</span>';
650                                     }
651                                 
652                                      return String.format('{0}', typeof(v) == 'object' ? v.format('d/M/Y') : v); 
653                                  },
654                                 editor : {
655                                     xtype: 'GridEditor',
656                                     xns: Roo.grid,
657                                     field : {
658                                         xtype: 'DateField',
659                                         xns: Roo.form,
660                                         format : 'd/M/Y',
661                                         useIso : true
662                                     }
663                                 }
664                             },
665                             {
666                                 xtype: 'ColumnModel',
667                                 xns: Roo.grid,
668                                 dataIndex : 'expitem_expcat_id',
669                                 header : 'Category',
670                                 width : 140,
671                                 renderer : function(v,x,r) { return String.format('{0}', r.data.expitem_expcat_id_expcat_descrip); },
672                                 editor : {
673                                     xtype: 'GridEditor',
674                                     xns: Roo.grid,
675                                     field : {
676                                         xtype: 'ComboBox',
677                                         xns: Roo.form,
678                                         allowBlank : false,
679                                         displayField : 'expcat_descrip',
680                                         editable : false,
681                                         emptyText : "Select expcat",
682                                         fieldLabel : 'expcat',
683                                         forceSelection : true,
684                                         hiddenName : 'expitem_expcat_id',
685                                         listWidth : 400,
686                                         loadingText : "Searching...",
687                                         minChars : 2,
688                                         name : 'expitem_expcat_id_expcat_descrip',
689                                         pageSize : 20,
690                                         qtip : "Select expcat",
691                                         queryParam : '',
692                                         selectOnFocus : true,
693                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{expcat_descrip}</b> </div>',
694                                         triggerAction : 'all',
695                                         typeAhead : true,
696                                         valueField : 'expcat_id',
697                                         width : 300,
698                                         store : {
699                                             xtype: 'Store',
700                                             xns: Roo.data,
701                                             listeners : {
702                                                 beforeload : function (_self, o){
703                                                     o.params = o.params || {};
704                                                     // set more here
705                                                 }
706                                             },
707                                             remoteSort : true,
708                                             sortInfo : { direction : 'ASC', field: 'expcat_descrip' },
709                                             proxy : {
710                                                 xtype: 'HttpProxy',
711                                                 xns: Roo.data,
712                                                 method : 'GET',
713                                                 url : baseURL + '/Roo/expcat.php'
714                                             },
715                                             reader : {
716                                                 xtype: 'JsonReader',
717                                                 xns: Roo.data,
718                                                 id : 'id',
719                                                 root : 'data',
720                                                 totalProperty : 'total',
721                                                 fields : [{"name":"id","type":"int"},{"name":"expcat_code","type":"string"}]
722                                             }
723                                         }
724                                     }
725                                 }
726                             },
727                             {
728                                 xtype: 'ColumnModel',
729                                 xns: Roo.grid,
730                                 dataIndex : 'expitem_memo',
731                                 header : 'Description',
732                                 width : 200,
733                                 renderer : function(v) { return String.format('{0}', v); },
734                                 editor : {
735                                     xtype: 'GridEditor',
736                                     xns: Roo.grid,
737                                     field : {
738                                         xtype: 'TextField',
739                                         xns: Roo.form
740                                     }
741                                 }
742                             },
743                             {
744                                 xtype: 'ColumnModel',
745                                 xns: Roo.grid,
746                                 dataIndex : 'expitem_curr_id',
747                                 header : 'Currency',
748                                 width : 75,
749                                 renderer : function(v,x,r) { return String.format('{0}', r.data.expitem_curr_id_curr_name); },
750                                 editor : {
751                                     xtype: 'GridEditor',
752                                     xns: Roo.grid,
753                                     field : {
754                                         xtype: 'ComboBox',
755                                         xns: Roo.form,
756                                         allowBlank : false,
757                                         displayField : 'curr_name',
758                                         editable : false,
759                                         emptyText : "Select curr_symbol",
760                                         fieldLabel : 'curr_symbol',
761                                         forceSelection : true,
762                                         hiddenName : 'expitem_curr_id',
763                                         listWidth : 400,
764                                         loadingText : "Searching...",
765                                         minChars : 2,
766                                         name : 'expitem_curr_id_curr_name',
767                                         pageSize : 20,
768                                         qtip : "Select curr_symbol",
769                                         queryParam : '',
770                                         selectOnFocus : true,
771                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
772                                         triggerAction : 'all',
773                                         typeAhead : true,
774                                         valueField : 'curr_id',
775                                         width : 300,
776                                         store : {
777                                             xtype: 'Store',
778                                             xns: Roo.data,
779                                             remoteSort : true,
780                                             sortInfo : { direction : 'ASC', field: 'id' },
781                                             listeners : {
782                                                 beforeload : function (_self, o){
783                                                     o.params = o.params || {};
784                                                     // set more here
785                                                 }
786                                             },
787                                             proxy : {
788                                                 xtype: 'HttpProxy',
789                                                 xns: Roo.data,
790                                                 method : 'GET',
791                                                 url : baseURL + '/Roo/curr_symbol.php'
792                                             },
793                                             reader : {
794                                                 xtype: 'JsonReader',
795                                                 xns: Roo.data,
796                                                 id : 'id',
797                                                 root : 'data',
798                                                 totalProperty : 'total',
799                                                 fields : [{"name":"id","type":"int"},{"name":"curr_name","type":"string"}]
800                                             }
801                                         }
802                                     }
803                                 }
804                             },
805                             {
806                                 xtype: 'ColumnModel',
807                                 xns: Roo.grid,
808                                 align : 'right',
809                                 dataIndex : 'expitem_amount_fc',
810                                 header : 'Amount',
811                                 width : 75,
812                                 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); },
813                                 editor : {
814                                     xtype: 'GridEditor',
815                                     xns: Roo.grid,
816                                     field : {
817                                         xtype: 'NumberField',
818                                         xns: Roo.form
819                                     }
820                                 }
821                             },
822                             {
823                                 xtype: 'ColumnModel',
824                                 xns: Roo.grid,
825                                 align : 'right',
826                                 dataIndex : 'expitem_tax',
827                                 header : 'Tax',
828                                 width : 75,
829                                 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); },
830                                 editor : {
831                                     xtype: 'GridEditor',
832                                     xns: Roo.grid,
833                                     field : {
834                                         xtype: 'NumberField',
835                                         xns: Roo.form
836                                     }
837                                 }
838                             },
839                             {
840                                 xtype: 'ColumnModel',
841                                 xns: Roo.grid,
842                                 align : 'right',
843                                 dataIndex : 'expitem_total',
844                                 header : 'Base Total',
845                                 width : 75,
846                                 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); }
847                             }
848                         ]
849                     }
850                 }
851             ],
852             center : {
853                 xtype: 'LayoutRegion',
854                 xns: Roo
855             },
856             north : {
857                 xtype: 'LayoutRegion',
858                 xns: Roo,
859                 height : 250
860             },
861             buttons : [
862                 {
863                     xtype: 'Button',
864                     xns: Roo,
865                     listeners : {
866                         click : function (_self, e)
867                         {
868                             _this.dialog.hide();
869                         }
870                     },
871                     text : "Cancel"
872                 },
873                 {
874                     xtype: 'Button',
875                     xns: Roo,
876                     listeners : {
877                         click : function (_self, e)
878                         {
879                             if (!_this.form.findField('expense_id').getValue()) {
880                                 Roo.MessageBox.alert("Error","You must save your expense report before printing/downloading");
881                                 return;        
882                             }
883                             new Pman.Download({
884                                 url : baseURL + '/Roo/expense',
885                                 method : 'GET',
886                                 params : {
887                                     expense_id : _this.form.findField('expense_id').getValue(),
888                                     _asExcel : 1
889                                 }
890                             });
891                             Roo.MessageBox.alert("Notice","Your report should be downloading now");
892                             
893                         }
894                     },
895                     text : "Download/Print"
896                 },
897                 {
898                     xtype: 'Button',
899                     xns: Roo,
900                     listeners : {
901                         click : function (_self, e)
902                         {
903                             // do some checks?
904                              
905                             _this.form.findField('expense_status').setValue('Pending Management Approval');
906                             _this.form.doAction("submit");
907                         
908                         },
909                         render : function (_self)
910                         {
911                             _this.postToManagement = _self;
912                         }
913                     },
914                     text : "Post to Management"
915                 },
916                 {
917                     xtype: 'Button',
918                     xns: Roo,
919                     listeners : {
920                         click : function (_self, e)
921                         {
922                             // do some checks?
923                               _this.form.findField('expense_status').setValue('Pending Accounting Approval');
924                          
925                             _this.form.doAction("submit");
926                         
927                         },
928                         render : function (_self)
929                         {
930                             _this.postToAccounts = _self;
931                         }
932                     },
933                     text : "Post to Accounts"
934                 },
935                 {
936                     xtype: 'Button',
937                     xns: Roo,
938                     listeners : {
939                         click : function (_self, e)
940                         {
941                          
942                             
943                             
944                             
945                             Roo.MessageBox.confirm("Confirm", "Post to General Ledger - this is very difficult to reverse so make sure it is correct",
946                                 function(b) {
947                                     if (b!='yes') { 
948                                         return;
949                                     }
950                                     _this.form.findField('_post').setValue(1);
951                                     _this.form.submit();
952                                 
953                                 }
954                             );
955                             
956                             // do some checks?
957                         
958                          
959                            // _this.form.doAction("submit");
960                         
961                         },
962                         render : function (_self)
963                         {
964                             _this.postToGL = _self;
965                         }
966                     },
967                     text : "Post to General Ledger"
968                 },
969                 {
970                     xtype: 'Button',
971                     xns: Roo,
972                     listeners : {
973                         click : function (_self, e)
974                         {
975                             // do some checks?
976                         
977                             if (!    _this.form.findField('expense_comments').getValue().length ) {
978                                 Roo.MessageBox.alert("Error", "Fill in a comment why it is getting rejected");
979                                 return;
980                             }
981                              
982                             _this.form.findField('expense_status').setValue('Draft');
983                             _this.form.doAction("submit");
984                         
985                         },
986                         render : function (_self)
987                         {
988                             _this.postToStaff = _self;
989                             
990                         }
991                     },
992                     text : "Reject / Require Clarification"
993                 },
994                 {
995                     xtype: 'Button',
996                     xns: Roo,
997                     listeners : {
998                         click : function (_self, e)
999                         {
1000                             // do some checks?
1001                              
1002                          
1003                             _this.form.doAction("submit");
1004                         
1005                         },
1006                         render : function (_self)
1007                         {
1008                             _this.saveBtn = _self;
1009                         }
1010                     },
1011                     text : "Save"
1012                 }
1013             ]
1014         });
1015     }
1016 };