1 //<script type="text/javascript">
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
5 Pman.Dialog.XtupleExpenses = {
10 show : function(data, cb)
18 this.dialog.show(this.data._el);
21 this.form.setValues(data);
22 this.form.fireEvent('actioncomplete', this.form, { type: 'setdata', data: data });
30 this.dialog = Roo.factory({
31 xtype: 'LayoutDialog',
38 title : "Edit / Create expense Report",
42 xtype: 'ContentPanel',
50 actioncomplete : function(_self,action)
53 var btns = ['postToManagement', 'postToAccounts','postToGL', 'postToStaff', 'saveBtn'];
54 var showhide = function()
56 Roo.each(btns, function(b) {
59 switch(_this.form.findField('expense_status').getValue()) {
61 _this['saveBtn'].show();
62 return; // do not show any button...
64 _this['saveBtn'].show();
65 _this['postToManagement'].show();
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')) {
77 _this['postToAccounts'].show();
78 _this['postToStaff'].show();
79 _this['saveBtn'].show();
81 case 'Pending Accounting Approval':
82 if (!Pman.Login.inGroup('Administrators')) {
86 // check if they are managmenet..
87 _this['postToGL'].show();
88 _this['postToStaff'].show();
89 _this['saveBtn'].show();
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 }});
104 _this.grid.ds.load({});
107 if (action.type == 'load') {
114 _this.grid.ds.load({});
117 if (action.type =='submit') {
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 });
130 if (_this.callback) {
131 _this.callback.call(_this, _this.form.getValues());
137 rendered : function (form)
143 style : 'margin:10px;',
144 url : baseURL + '/Roo/expense.php',
155 style : 'width:380px',
161 name : 'expense_number',
168 fieldLabel : 'Due Date',
170 name : 'expense_trandate',
176 fieldLabel : 'Summary',
177 name : 'expense_memo',
183 fieldLabel : 'Status',
184 name : 'expense_status',
194 style : 'clear:both;float:left;',
199 fieldLabel : 'Comments / For Review etc.',
200 name : 'expense_comments',
217 style : 'width:250px;margin-left:10px',
223 name : 'expense_emp_id_emp_name',
231 legend : "Financial Details",
232 style : 'width:250px;margin-left:10px',
237 fieldLabel : 'Advance Paid',
238 name : 'expense_advance',
244 fieldLabel : 'Amount',
245 name : 'expense_amount_ro',
253 name : 'expense_tax_ro',
260 fieldLabel : 'Total',
261 name : 'expense_total_ro',
274 displayField : 'accnt_descrip',
276 emptyText : "Select accnt",
277 fieldLabel : 'Paid from Bank Account (accounting only)',
278 forceSelection : true,
279 hiddenName : 'expense_accnt_id',
281 loadingText : "Searching...",
283 name : 'expense_accnt_id_accnt_descrip',
285 qtip : "Select accnt",
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',
296 beforeload : function (_self, o){
297 o.params = o.params || {};
299 o.params.accnt_subaccnttype_code = 'CA';
303 sortInfo : { direction : 'ASC', field: 'accnt_descrip' },
308 url : baseURL + '/Roo/accnt.php'
315 totalProperty : 'total',
316 fields : [{"name":"id","type":"int"},{"name":"accnt_number","type":"string"}]
329 name : 'base_curr_id'
334 name : 'base_curr_name'
339 name : 'def_expcat_id'
344 name : 'def_expcat_descrip'
349 name : 'expense_emp_id'
369 activate : function() {
372 // _this.grid.footer.onClick('first');
380 tableName : 'expitem',
389 //_this.dialog = Pman.Dialog.FILL_IN
390 if (_this.panel.active) {
391 //this.gi.onClick('first');
394 rowdblclick : function (_self, rowIndex, e)
396 if (!_this.dialog) return;
397 _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
398 _this.grid.footer.onClick('first');
401 afteredit : function (e)
404 if (e.field == 'expitem_date') {
405 e.record.set('expitem_date', Date.parseDate(e.value, 'Y-m-d'));
412 autoExpandColumn : 'expitem_memo',
419 beforeload : function (_self, options)
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");
429 _this.grid.view.el.mask("Save First");
434 update : function (_self, record, operation)
436 if (operation != 'commit') {
439 var send = Roo.apply({}, record.data);
441 send.expitem_date = typeof(send.expitem_date) == 'object' ? send.expitem_date.format('Y-m-d') : send.expitem_date;
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);
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);
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);
463 _this.form.setValues(t);
469 url : baseURL + '/Roo/expitem',
471 success : function(res) {
472 if (!record.data.expitem_id) {
473 record.set('expitem_id', res.data.expitem_id);
475 record.set('expitem_total', res.data.expitem_total);
485 sortInfo : { field : 'expitem_row', direction: 'ASC' },
490 url : baseURL + '/Roo/expitem.php'
495 totalProperty : 'total',
500 'name': 'expitem_id',
504 'name': 'expitem_expense_id',
508 'name': 'expitem_curr_id',
512 'name': 'expitem_expcat_id',
516 'name': 'expitem_row',
520 'name': 'expitem_amount',
524 'name': 'expitem_amount_fc',
528 'name': 'expitem_tax',
532 'name': 'expitem_total',
536 'name': 'expitem_date',
538 'dateFormat': 'Y-m-d'
541 'name': 'expitem_is_billable',
545 'name': 'expitem_memo',
564 var grid = _this.grid;
565 var r = grid.getDataSource().reader.newRow({
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
579 var lr = grid.ds.getCount()
580 grid.getDataSource().insert(lr, r);
581 grid.startEditing(lr, 1);
584 cls : 'x-btn-text-icon',
586 icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
598 var ce = _this.grid.selModel.getSelectedCell();
600 Roo.MessageBox.alert("Error", "Select a line to delete");
603 var rec = _this.grid.ds.getAt(ce[0]);
604 if (!rec.data.expitem_id) {
605 _this.grid.ds.remove(rec);
612 url : baseURL + '/Roo/expitem',
615 _delete : rec.data.expitem_id
619 _this.grid.ds.remove(rec);
626 cls : 'x-btn-text-icon',
628 icon : rootURL + '/Pman/templates/images/trash.gif'
634 xtype: 'ColumnModel',
636 dataIndex : 'expitem_row',
639 renderer : function(v) { return String.format('{0}', v); }
642 xtype: 'ColumnModel',
644 dataIndex : 'expitem_date',
647 renderer : function(v) {
649 return '<span style="color:red">' + "NO DATE" + '</span>';
652 return String.format('{0}', typeof(v) == 'object' ? v.format('d/M/Y') : v);
666 xtype: 'ColumnModel',
668 dataIndex : 'expitem_expcat_id',
671 renderer : function(v,x,r) { return String.format('{0}', r.data.expitem_expcat_id_expcat_descrip); },
679 displayField : 'expcat_descrip',
681 emptyText : "Select expcat",
682 fieldLabel : 'expcat',
683 forceSelection : true,
684 hiddenName : 'expitem_expcat_id',
686 loadingText : "Searching...",
688 name : 'expitem_expcat_id_expcat_descrip',
690 qtip : "Select expcat",
692 selectOnFocus : true,
693 tpl : '<div class="x-grid-cell-text x-btn button"><b>{expcat_descrip}</b> </div>',
694 triggerAction : 'all',
696 valueField : 'expcat_id',
702 beforeload : function (_self, o){
703 o.params = o.params || {};
708 sortInfo : { direction : 'ASC', field: 'expcat_descrip' },
713 url : baseURL + '/Roo/expcat.php'
720 totalProperty : 'total',
721 fields : [{"name":"id","type":"int"},{"name":"expcat_code","type":"string"}]
728 xtype: 'ColumnModel',
730 dataIndex : 'expitem_memo',
731 header : 'Description',
733 renderer : function(v) { return String.format('{0}', v); },
744 xtype: 'ColumnModel',
746 dataIndex : 'expitem_curr_id',
749 renderer : function(v,x,r) { return String.format('{0}', r.data.expitem_curr_id_curr_name); },
757 displayField : 'curr_name',
759 emptyText : "Select curr_symbol",
760 fieldLabel : 'curr_symbol',
761 forceSelection : true,
762 hiddenName : 'expitem_curr_id',
764 loadingText : "Searching...",
766 name : 'expitem_curr_id_curr_name',
768 qtip : "Select curr_symbol",
770 selectOnFocus : true,
771 tpl : '<div class="x-grid-cell-text x-btn button"><b>{curr_name}</b> </div>',
772 triggerAction : 'all',
774 valueField : 'curr_id',
780 sortInfo : { direction : 'ASC', field: 'id' },
782 beforeload : function (_self, o){
783 o.params = o.params || {};
791 url : baseURL + '/Roo/curr_symbol.php'
798 totalProperty : 'total',
799 fields : [{"name":"id","type":"int"},{"name":"curr_name","type":"string"}]
806 xtype: 'ColumnModel',
809 dataIndex : 'expitem_amount_fc',
812 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); },
817 xtype: 'NumberField',
823 xtype: 'ColumnModel',
826 dataIndex : 'expitem_tax',
829 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); },
834 xtype: 'NumberField',
840 xtype: 'ColumnModel',
843 dataIndex : 'expitem_total',
844 header : 'Base Total',
846 renderer : function(v) { return String.format('{0}', (1*v).toFixed(2)); }
853 xtype: 'LayoutRegion',
857 xtype: 'LayoutRegion',
866 click : function (_self, e)
877 click : function (_self, e)
879 if (!_this.form.findField('expense_id').getValue()) {
880 Roo.MessageBox.alert("Error","You must save your expense report before printing/downloading");
884 url : baseURL + '/Roo/expense',
887 expense_id : _this.form.findField('expense_id').getValue(),
891 Roo.MessageBox.alert("Notice","Your report should be downloading now");
895 text : "Download/Print"
901 click : function (_self, e)
905 _this.form.findField('expense_status').setValue('Pending Management Approval');
906 _this.form.doAction("submit");
909 render : function (_self)
911 _this.postToManagement = _self;
914 text : "Post to Management"
920 click : function (_self, e)
923 _this.form.findField('expense_status').setValue('Pending Accounting Approval');
925 _this.form.doAction("submit");
928 render : function (_self)
930 _this.postToAccounts = _self;
933 text : "Post to Accounts"
939 click : function (_self, e)
945 Roo.MessageBox.confirm("Confirm", "Post to General Ledger - this is very difficult to reverse so make sure it is correct",
950 _this.form.findField('_post').setValue(1);
959 // _this.form.doAction("submit");
962 render : function (_self)
964 _this.postToGL = _self;
967 text : "Post to General Ledger"
973 click : function (_self, e)
977 if (! _this.form.findField('expense_comments').getValue().length ) {
978 Roo.MessageBox.alert("Error", "Fill in a comment why it is getting rejected");
982 _this.form.findField('expense_status').setValue('Draft');
983 _this.form.doAction("submit");
986 render : function (_self)
988 _this.postToStaff = _self;
992 text : "Reject / Require Clarification"
998 click : function (_self, e)
1003 _this.form.doAction("submit");
1006 render : function (_self)
1008 _this.saveBtn = _self;