{ "id": "roo-file-6", "name": "Pman.Dialog.XtupleExpenses", "parent": "", "title": "", "path": "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Dialog.XtupleExpenses.bjs", "items": [ { "closable": false, "collapsible": false, "height": 640, "modal": true, "resizable": false, "title": "Edit / Create expense Report", "width": 900, "xtype": "LayoutDialog", "|xns": "Roo", "items": [ { "|xns": "Roo", "xtype": "LayoutRegion", "*prop": "center" }, { "*prop": "north", "height": 250, "xtype": "LayoutRegion", "|xns": "Roo" }, { "region": "north", "xtype": "ContentPanel", "|xns": "Roo", "items": [ { "listeners": { "|actioncomplete": "function(_self,action)\n{\n \n var btns = ['postToManagement', 'postToAccounts','postToGL', 'postToStaff', 'saveBtn'];\n var showhide = function()\n {\n Roo.each(btns, function(b) {\n _this[b].hide();\n });\n switch(_this.form.findField('expense_status').getValue()) {\n case '':\n _this['saveBtn'].show();\n return; // do not show any button...\n case 'Draft': \n _this['saveBtn'].show();\n _this['postToManagement'].show();\n break;\n \n \n case 'Pending Management Approval':\n case 'Pending Supervisor Approval': // old system..\n // check if they are managmenet..\n // eg. have to be in TIER2\n if (!Pman.Login.inGroup('TIER2') && !Pman.Login.inGroup('TIER1') && \n !Pman.Login.inGroup('Administrators')) {\n return;\n }\n _this['postToAccounts'].show();\n _this['postToStaff'].show(); \n _this['saveBtn'].show();\n break;\n case 'Pending Accounting Approval':\n if (!Pman.Login.inGroup('Administrators')) {\n return;\n }\n \n // check if they are managmenet..\n _this['postToGL'].show();\n _this['postToStaff'].show(); \n _this['saveBtn'].show(); \n break;\n \n \n }\n }\n \n if (action.type == 'setdata') {\n //_this.dialog.el.mask(\"Loading\");\n if (_this.data.expense_id) {\n this.load({ method: 'GET', params: { '_id' : _this.data.expense_id }});\n \n return;\n }\n showhide();\n _this.grid.ds.load({});\n return;\n }\n if (action.type == 'load') {\n \n \n showhide();\n \n \n \n _this.grid.ds.load({});\n return;\n }\n if (action.type =='submit') {\n \n \n if (! (1 * _this.form.findField('expense_id').getValue()) ) {\n Roo.log(\"fire event\");\n _this.data = action.result.data;\n this.fireEvent('actioncomplete', this, { type: 'setdata', data: action.result.data });\n return;\n }\n \n \n _this.dialog.hide();\n \n if (_this.callback) {\n _this.callback.call(_this, _this.form.getValues());\n }\n _this.form.reset();\n return;\n }\n}\n", "|rendered": "function (form)\n{\n _this.form= form;\n}\n" }, "method": "POST", "style": "margin:10px;", "xtype": "Form", "|url": "baseURL + '/Roo/expense.php'", "|xns": "Roo.form", "items": [ { "width": 400, "xtype": "Column", "|xns": "Roo.form", "items": [ { "legend": "Summary", "style": "width:380px", "xtype": "FieldSet", "|xns": "Roo.form", "items": [ { "fieldLabel": "Ref#", "name": "expense_number", "readOnly": true, "width": 200, "xtype": "TextField", "|xns": "Roo.form" }, { "fieldLabel": "Due Date", "format": "Y-m-d", "name": "expense_trandate", "width": 100, "xtype": "DateField", "|xns": "Roo.form" }, { "fieldLabel": "Summary", "name": "expense_memo", "width": 200, "xtype": "TextField", "|xns": "Roo.form" }, { "fieldLabel": "Status", "name": "expense_status", "readOnly": true, "width": 200, "xtype": "TextField", "|xns": "Roo.form" } ] }, { "labelAlign": "top", "style": "clear:both;float:left;", "xtype": "Row", "|xns": "Roo.form", "items": [ { "fieldLabel": "Comments / For Review etc.", "name": "expense_comments", "width": 400, "xtype": "TextArea", "|xns": "Roo.form" } ] } ] }, { "width": 400, "xtype": "Column", "|xns": "Roo.form", "items": [ { "labelWidth": 50, "legend": "Employee", "style": "width:250px;margin-left:10px", "xtype": "FieldSet", "|xns": "Roo.form", "items": [ { "fieldLabel": "Name", "name": "expense_emp_id_emp_name", "readOnly": true, "xtype": "TextField", "|xns": "Roo.form" } ] }, { "legend": "Financial Details", "style": "width:250px;margin-left:10px", "xtype": "FieldSet", "|xns": "Roo.form", "items": [ { "fieldLabel": "Advance Paid", "name": "expense_advance", "width": 75, "xtype": "TextField", "|xns": "Roo.form" }, { "fieldLabel": "Amount", "name": "expense_amount_ro", "readOnly": true, "width": 75, "xtype": "TextField", "|xns": "Roo.form" }, { "fieldLabel": "Tax", "name": "expense_tax_ro", "readOnly": true, "width": 75, "xtype": "TextField", "|xns": "Roo.form" }, { "fieldLabel": "Total", "name": "expense_total_ro", "readOnly": true, "width": 75, "xtype": "TextField", "|xns": "Roo.form" }, { "labelAlign": "top", "xtype": "Row", "|xns": "Roo.form", "items": [ { "allowBlank": true, "displayField": "accnt_descrip", "editable": false, "emptyText": "Select accnt", "fieldLabel": "Paid from Bank Account (accounting only)", "forceSelection": true, "hiddenName": "expense_accnt_id", "listWidth": 400, "loadingText": "Searching...", "minChars": 2, "name": "expense_accnt_id_accnt_descrip", "pageSize": 20, "qtip": "Select accnt", "queryParam": "", "selectOnFocus": true, "tpl": "
{accnt_descrip}
", "triggerAction": "all", "valueField": "accnt_id", "width": 250, "xtype": "ComboBox", "|xns": "Roo.form", "items": [ { "listeners": { "|beforeload": "function (_self, o){\n o.params = o.params || {};\n // set more here\n o.params.accnt_subaccnttype_code = 'CA';\n}\n" }, "*prop": "store", "remoteSort": true, "xtype": "Store", "|sortInfo": "{ direction : 'ASC', field: 'accnt_descrip' }", "|xns": "Roo.data", "items": [ { "*prop": "proxy", "xtype": "HttpProxy", "method": "GET", "|xns": "Roo.data", "|url": "baseURL + '/Roo/accnt.php'" }, { "*prop": "reader", "xtype": "JsonReader", "|xns": "Roo.data", "id": "id", "root": "data", "totalProperty": "total", "|fields": "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"accnt_number\",\"type\":\"string\"}]" } ] } ] } ] } ] } ] }, { "name": "base_curr_id", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "base_curr_name", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "def_expcat_id", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "def_expcat_descrip", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "expense_emp_id", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "expense_id", "xtype": "Hidden", "|xns": "Roo.form" }, { "name": "_post", "xtype": "Hidden", "|xns": "Roo.form" } ] } ] }, { "listeners": { "|activate": "function() {\n _this.panel = this;\n if (_this.grid) {\n // _this.grid.footer.onClick('first');\n }\n}" }, "background": false, "fitContainer": true, "fitToframe": true, "region": "center", "tableName": "expitem", "title": "expitem", "xtype": "GridPanel", "|xns": "Roo", "items": [ { "listeners": { "|render": "function() \n{\n _this.grid = this; \n //_this.dialog = Pman.Dialog.FILL_IN\n if (_this.panel.active) {\n //this.gi.onClick('first');\n }\n}", "|rowdblclick": "function (_self, rowIndex, e)\n{\n if (!_this.dialog) return;\n _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {\n _this.grid.footer.onClick('first');\n }); \n}\n", "afteredit": "function (e)\n{\n \n if (e.field == 'expitem_date') {\n e.record.set('expitem_date', Date.parseDate(e.value, 'Y-m-d'));\n \n } \n \n e.record.commit();\n}" }, "*prop": "grid", "autoExpandColumn": "expitem_memo", "clicksToEdit": 1, "loadMask": true, "xtype": "EditorGrid", "|xns": "Roo.grid", "items": [ { "listeners": { "beforeload": "function (_self, options)\n{\n \n options.params = options.param || {};\n options.params.limit = 999;\n _this.grid.view.el.unmask();\n options.params.expitem_expense_id = _this.form.findField('expense_id').getValue() *1 ;\n if (! options.params.expitem_expense_id) {\n Roo.log(\"no expense id yet\");\n this.removeAll();\n _this.grid.view.el.mask(\"Save First\");\n return false;\n }\n \n}", "update": "function (_self, record, operation)\n{\n if (operation != 'commit') {\n return;\n }\n var send = Roo.apply({}, record.data);\n // fix date...\n send.expitem_date = typeof(send.expitem_date) == 'object' ? send.expitem_date.format('Y-m-d') : send.expitem_date;\n \n \n function updateTotals(){\n var t = { expense_total_ro : 0 , expense_amount_ro : 0, expense_tax_ro : 0 }\n _this.grid.ds.each(function(r) {\n var fc_total = (r.data.expitem_tax * 1) + (r.data.expitem_amount_fc * 1);\n if (!fc_total) {\n return;\n }\n var base_total = r.data.expitem_total * 1;\n var rate = base_total / fc_total;\n t.expense_total_ro += base_total;\n t.expense_amount_ro += (r.data.expitem_amount_fc * rate);\n t.expense_tax_ro += (r.data.expitem_tax * rate);\n \n });\n t.expense_total_ro = t.expense_total_ro.toFixed(2);\n t.expense_amount_ro = t.expense_amount_ro.toFixed(2);\n t.expense_tax_ro = t.expense_tax_ro.toFixed(2);\n \n \n _this.form.setValues(t);\n }\n \n \n new Pman.Request( {\n method : 'POST' ,\n url : baseURL + '/Roo/expitem',\n params :send,\n success : function(res) {\n if (!record.data.expitem_id) {\n record.set('expitem_id', res.data.expitem_id);\n }\n record.set('expitem_total', res.data.expitem_total);\n updateTotals();\n }\n });\n \n \n \n}" }, "*prop": "dataSource", "remoteSort": true, "xtype": "Store", "|sortInfo": "{ field : 'expitem_row', direction: 'ASC' }", "|xns": "Roo.data", "items": [ { "*prop": "proxy", "xtype": "HttpProxy", "method": "GET", "|url": "baseURL + '/Roo/expitem.php'", "|xns": "Roo.data" }, { "|xns": "Roo.data", "xtype": "JsonReader", "totalProperty": "total", "root": "data", "*prop": "reader", "id": "id", "|fields": "[\n {\n 'name': 'expitem_id',\n 'type': 'int'\n },\n {\n 'name': 'expitem_expense_id',\n 'type': 'int'\n },\n {\n 'name': 'expitem_curr_id',\n 'type': 'int'\n },\n {\n 'name': 'expitem_expcat_id',\n 'type': 'int'\n },\n {\n 'name': 'expitem_row',\n 'type': 'int'\n },\n {\n 'name': 'expitem_amount',\n 'type': 'float'\n },\n {\n 'name': 'expitem_amount_fc',\n 'type': 'float'\n },\n {\n 'name': 'expitem_tax',\n 'type': 'float'\n },\n {\n 'name': 'expitem_total',\n 'type': 'float'\n },\n {\n 'name': 'expitem_date',\n 'type': 'date',\n 'dateFormat': 'Y-m-d'\n },\n {\n 'name': 'expitem_is_billable',\n 'type': 'int'\n },\n {\n 'name': 'expitem_memo',\n 'type': 'string'\n }\n]" } ] }, { "*prop": "toolbar", "xtype": "Toolbar", "|xns": "Roo", "items": [ { "listeners": { "|click": "function()\n{\n \n \n \n var grid = _this.grid;\n var r = grid.getDataSource().reader.newRow({\n expitem_id : 0,\n expitem_expense_id : _this.form.findField('expense_id').getValue(),\n expitem_row : grid.ds.getCount() + 1,\n expitem_date : new Date(),\n expitem_curr_id : _this.form.findField('base_curr_id').getValue(),\n expitem_curr_id_curr_name : _this.form.findField('base_curr_name').getValue(),\n expitem_expcat_id : _this.form.findField('def_expcat_id').getValue(),\n expitem_expcat_id_expcat_descrip : _this.form.findField('def_expcat_descrip').getValue(),\n expitem_amount_tax : 0.0\n \n });\n \n grid.stopEditing();\n var lr = grid.ds.getCount()\n grid.getDataSource().insert(lr, r); \n grid.startEditing(lr, 1); \n}" }, "cls": "x-btn-text-icon", "text": "Add", "xtype": "Button", "|icon": "Roo.rootURL + 'images/default/dd/drop-add.gif'", "|xns": "Roo.Toolbar" }, { "|xns": "Roo.Toolbar", "xtype": "Fill" }, { "listeners": { "|click": "function()\n{\n var ce = _this.grid.selModel.getSelectedCell();\n if (!ce) {\n Roo.MessageBox.alert(\"Error\", \"Select a line to delete\");\n return;\n }\n var rec = _this.grid.ds.getAt(ce[0]);\n if (!rec.data.expitem_id) {\n _this.grid.ds.remove(rec);\n return;\n }\n \n \n new Pman.Request({\n mask : 'Deleting',\n url : baseURL + '/Roo/expitem',\n method : 'POST',\n params : {\n _delete : rec.data.expitem_id\n },\n success : function()\n {\n _this.grid.ds.remove(rec); \n }\n });\n \n \n}\n " }, "cls": "x-btn-text-icon", "text": "Delete", "xtype": "Button", "|icon": "rootURL + '/Pman/templates/images/trash.gif'", "|xns": "Roo.Toolbar" } ] }, { "*prop": "colModel[]", "dataIndex": "expitem_row", "header": "Line#", "width": 50, "xtype": "ColumnModel", "|renderer": "function(v) { return String.format('{0}', v); }", "|xns": "Roo.grid" }, { "*prop": "colModel[]", "dataIndex": "expitem_date", "header": "Date", "width": 75, "xtype": "ColumnModel", "|renderer": "function(v) {\n if (!v) {\n return '' + \"NO DATE\" + '';\n }\n\n return String.format('{0}', typeof(v) == 'object' ? v.format('d/M/Y') : v); \n }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "*prop": "field", "format": "d/M/Y", "useIso": true, "xtype": "DateField", "|xns": "Roo.form" } ] } ] }, { "*prop": "colModel[]", "dataIndex": "expitem_expcat_id", "header": "Category", "width": 140, "xtype": "ColumnModel", "|renderer": "function(v,x,r) { return String.format('{0}', r.data.expitem_expcat_id_expcat_descrip); }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "*prop": "field", "allowBlank": false, "displayField": "expcat_descrip", "editable": false, "emptyText": "Select expcat", "fieldLabel": "expcat", "forceSelection": true, "hiddenName": "expitem_expcat_id", "listWidth": 400, "loadingText": "Searching...", "minChars": 2, "name": "expitem_expcat_id_expcat_descrip", "pageSize": 20, "qtip": "Select expcat", "queryParam": "", "selectOnFocus": true, "tpl": "
{expcat_descrip}
", "triggerAction": "all", "typeAhead": true, "valueField": "expcat_id", "width": 300, "xtype": "ComboBox", "|xns": "Roo.form", "items": [ { "listeners": { "|beforeload": "function (_self, o){\n o.params = o.params || {};\n // set more here\n}\n" }, "*prop": "store", "remoteSort": true, "xtype": "Store", "|sortInfo": "{ direction : 'ASC', field: 'expcat_descrip' }", "|xns": "Roo.data", "items": [ { "*prop": "proxy", "xtype": "HttpProxy", "method": "GET", "|xns": "Roo.data", "|url": "baseURL + '/Roo/expcat.php'" }, { "*prop": "reader", "xtype": "JsonReader", "|xns": "Roo.data", "id": "id", "root": "data", "totalProperty": "total", "|fields": "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"expcat_code\",\"type\":\"string\"}]" } ] } ] } ] } ] }, { "*prop": "colModel[]", "dataIndex": "expitem_memo", "header": "Description", "width": 200, "xtype": "ColumnModel", "|renderer": "function(v) { return String.format('{0}', v); }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "|xns": "Roo.form", "xtype": "TextField", "*prop": "field" } ] } ] }, { "*prop": "colModel[]", "dataIndex": "expitem_curr_id", "header": "Currency", "width": 75, "xtype": "ColumnModel", "|renderer": "function(v,x,r) { return String.format('{0}', r.data.expitem_curr_id_curr_name); }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "*prop": "field", "allowBlank": false, "displayField": "curr_name", "editable": false, "emptyText": "Select curr_symbol", "fieldLabel": "curr_symbol", "forceSelection": true, "hiddenName": "expitem_curr_id", "listWidth": 400, "loadingText": "Searching...", "minChars": 2, "name": "expitem_curr_id_curr_name", "pageSize": 20, "qtip": "Select curr_symbol", "queryParam": "", "selectOnFocus": true, "tpl": "
{curr_name}
", "triggerAction": "all", "typeAhead": true, "valueField": "curr_id", "width": 300, "xtype": "ComboBox", "|xns": "Roo.form", "items": [ { "*prop": "store", "xtype": "Store", "|xns": "Roo.data", "remoteSort": true, "|sortInfo": "{ direction : 'ASC', field: 'id' }", "listeners": { "|beforeload": "function (_self, o){\n o.params = o.params || {};\n // set more here\n}\n" }, "items": [ { "*prop": "proxy", "xtype": "HttpProxy", "method": "GET", "|xns": "Roo.data", "|url": "baseURL + '/Roo/curr_symbol.php'" }, { "*prop": "reader", "xtype": "JsonReader", "|xns": "Roo.data", "id": "id", "root": "data", "totalProperty": "total", "|fields": "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"curr_name\",\"type\":\"string\"}]" } ] } ] } ] } ] }, { "*prop": "colModel[]", "align": "right", "dataIndex": "expitem_amount_fc", "header": "Amount", "width": 75, "xtype": "ColumnModel", "|renderer": "function(v) { return String.format('{0}', (1*v).toFixed(2)); }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "|xns": "Roo.form", "xtype": "NumberField", "*prop": "field" } ] } ] }, { "*prop": "colModel[]", "align": "right", "dataIndex": "expitem_tax", "header": "Tax", "width": 75, "xtype": "ColumnModel", "|renderer": "function(v) { return String.format('{0}', (1*v).toFixed(2)); }", "|xns": "Roo.grid", "items": [ { "|xns": "Roo.grid", "xtype": "GridEditor", "*prop": "editor", "items": [ { "|xns": "Roo.form", "xtype": "NumberField", "*prop": "field" } ] } ] }, { "*prop": "colModel[]", "align": "right", "dataIndex": "expitem_total", "header": "Base Total", "width": 75, "xtype": "ColumnModel", "|renderer": "function(v) { return String.format('{0}', (1*v).toFixed(2)); }", "|xns": "Roo.grid" } ] } ] }, { "listeners": { "click": "function (_self, e)\n{\n _this.dialog.hide();\n}" }, "*prop": "buttons[]", "text": "Cancel", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n if (!_this.form.findField('expense_id').getValue()) {\n Roo.MessageBox.alert(\"Error\",\"You must save your expense report before printing/downloading\");\n return; \n }\n new Pman.Download({\n url : baseURL + '/Roo/expense',\n method : 'GET',\n params : {\n expense_id : _this.form.findField('expense_id').getValue(),\n _asExcel : 1\n }\n });\n Roo.MessageBox.alert(\"Notice\",\"Your report should be downloading now\");\n \n}" }, "*prop": "buttons[]", "text": "Download/Print", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n // do some checks?\n \n _this.form.findField('expense_status').setValue('Pending Management Approval');\n _this.form.doAction(\"submit\");\n\n}", "render": "function (_self)\n{\n _this.postToManagement = _self;\n}" }, "*prop": "buttons[]", "text": "Post to Management", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n // do some checks?\n _this.form.findField('expense_status').setValue('Pending Accounting Approval');\n \n _this.form.doAction(\"submit\");\n\n}", "render": "function (_self)\n{\n _this.postToAccounts = _self;\n}" }, "*prop": "buttons[]", "text": "Post to Accounts", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n \n \n \n \n Roo.MessageBox.confirm(\"Confirm\", \"Post to General Ledger - this is very difficult to reverse so make sure it is correct\",\n function(b) {\n if (b!='yes') { \n return;\n }\n _this.form.findField('_post').setValue(1);\n _this.form.submit();\n \n }\n );\n \n // do some checks?\n\n \n // _this.form.doAction(\"submit\");\n\n}", "render": "function (_self)\n{\n _this.postToGL = _self;\n}" }, "*prop": "buttons[]", "text": "Post to General Ledger", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n // do some checks?\n\n if (! _this.form.findField('expense_comments').getValue().length ) {\n Roo.MessageBox.alert(\"Error\", \"Fill in a comment why it is getting rejected\");\n return;\n }\n \n _this.form.findField('expense_status').setValue('Draft');\n _this.form.doAction(\"submit\");\n\n}", "render": "function (_self)\n{\n _this.postToStaff = _self;\n \n}" }, "*prop": "buttons[]", "text": "Reject / Require Clarification", "xtype": "Button", "|xns": "Roo" }, { "listeners": { "click": "function (_self, e)\n{\n // do some checks?\n \n \n _this.form.doAction(\"submit\");\n\n}", "render": "function (_self)\n{\n _this.saveBtn = _self;\n}" }, "*prop": "buttons[]", "text": "Save", "xtype": "Button", "|xns": "Roo" } ] } ], "permname": "", "modOrder": "001" }