From 7b9b897f9b44b502eb21bfe7cd5a64d979be4ba1 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 11 Jun 2018 16:50:34 +0530 Subject: [PATCH] Add Report View and Dynamic Link --- .eslintrc.js | 5 +- accounting/utils.js | 4 +- reports/GeneralLedger/viewConfig.js | 36 ++++++++++++ reports/Register/RegisterView.js | 2 +- reports/index.js | 2 +- reports/view.js | 71 +---------------------- src/App.vue | 1 + src/components/List/List.vue | 3 +- src/components/Report.vue | 52 +++++++++++++++++ src/components/ReportFilters.vue | 43 ++++++++++++++ src/components/Sidebar.vue | 7 ++- src/components/controls/Autocomplete.vue | 1 + src/components/controls/Base.vue | 2 +- src/components/controls/Date.vue | 3 +- src/components/controls/DynamicLink.vue | 14 +++++ src/components/controls/FrappeControl.vue | 2 + src/components/controls/Link.vue | 7 ++- src/main.js | 2 + src/router/index.js | 12 ++-- src/sidebar.js | 2 +- 20 files changed, 181 insertions(+), 90 deletions(-) create mode 100644 reports/GeneralLedger/viewConfig.js create mode 100644 src/components/Report.vue create mode 100644 src/components/ReportFilters.vue create mode 100644 src/components/controls/DynamicLink.vue diff --git a/.eslintrc.js b/.eslintrc.js index 2121acee..e297ea07 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,6 +25,9 @@ module.exports = { 'generator-star-spacing': 'off', // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', - 'semi': 'off' + 'semi': 'on', + 'indent': 'off', + // 'indent': ["error", 4], + 'space-before-function-paren': 'off' } } diff --git a/accounting/utils.js b/accounting/utils.js index f14f7c3d..6bc30525 100644 --- a/accounting/utils.js +++ b/accounting/utils.js @@ -11,5 +11,5 @@ module.exports = { } }; } - }, -} \ No newline at end of file + } +} diff --git a/reports/GeneralLedger/viewConfig.js b/reports/GeneralLedger/viewConfig.js new file mode 100644 index 00000000..bab2513f --- /dev/null +++ b/reports/GeneralLedger/viewConfig.js @@ -0,0 +1,36 @@ +const title = 'General Ledger'; +module.exports = { + title: title, + method: 'general-ledger', + filterFields: [ + { + fieldtype: 'Select', + options: ['', 'Invoice', 'Payment'], + label: 'Reference Type', + fieldname: 'referenceType' + }, + { + fieldtype: 'DynamicLink', + references: 'referenceType', + label: 'Reference Name', + fieldname: 'referenceName' + }, + { fieldtype: 'Link', target: 'Account', label: 'Account', fieldname: 'account' }, + { fieldtype: 'Link', target: 'Party', label: 'Party', fieldname: 'party' }, + { fieldtype: 'Date', label: 'From Date', fieldname: 'fromDate' }, + { fieldtype: 'Date', label: 'To Date', fieldname: 'toDate' } + ], + getColumns() { + return [ + { label: 'Date', fieldtype: 'Date' }, + { label: 'Account', fieldtype: 'Link' }, + { label: 'Debit', fieldtype: 'Currency' }, + { label: 'Credit', fieldtype: 'Currency' }, + { label: 'Balance', fieldtype: 'Currency' }, + { label: 'Reference Type', fieldtype: 'Data' }, + { label: 'Reference Name', fieldtype: 'Data' }, + { label: 'Party', fieldtype: 'Link' }, + { label: 'Description', fieldtype: 'Data' } + ] + } +} diff --git a/reports/Register/RegisterView.js b/reports/Register/RegisterView.js index b42d1706..1f9df304 100644 --- a/reports/Register/RegisterView.js +++ b/reports/Register/RegisterView.js @@ -9,7 +9,7 @@ module.exports = class RegisterView extends ReportPage { title, filterFields: [ {fieldtype: 'Date', fieldname: 'fromDate', label: 'From Date', required: 1}, - {fieldtype: 'Date', fieldname: 'toDate', label: 'To Date', required: 1} + {fieldtype: 'Date', fieldname: 'toDate', label: 'To Date', required: 1} ] }); diff --git a/reports/index.js b/reports/index.js index 9fe3b8e4..385b8551 100644 --- a/reports/index.js +++ b/reports/index.js @@ -33,7 +33,7 @@ function registerReportMethods() { { method: 'purchase-register', class: PurchaseRegister - }, + } ]; reports.forEach(report => { diff --git a/reports/view.js b/reports/view.js index 00505aa1..631d754b 100644 --- a/reports/view.js +++ b/reports/view.js @@ -1,70 +1,3 @@ -const frappe = require('frappejs'); -const GeneralLedgerView = require('../reports/GeneralLedger/GeneralLedgerView'); -const ProfitAndLossView = require('./ProfitAndLoss/ProfitAndLossView'); -const BalanceSheetView = require('./BalanceSheet/BalanceSheetView'); -const TrialBalanceView = require('./TrialBalance/TrialBalanceView'); -const SalesRegisterView = require('./SalesRegister/SalesRegisterView'); -const PurchaseRegisterView = require('./PurchaseRegister/PurchaseRegisterView'); -const AccountsReceivableView = require('./AccountsReceivablePayable/AccountsReceivableView'); -const AccountsPayableView = require('./AccountsReceivablePayable/AccountsPayableView'); - -// called on client side -function registerReportRoutes() { - frappe.router.add('report/general-ledger', async (params) => { - if (!frappe.views.GeneralLedger) { - frappe.views.GeneralLedger = new GeneralLedgerView(); - } - await frappe.views.GeneralLedger.show(params); - }); - - frappe.router.add('report/profit-and-loss', async (params) => { - if (!frappe.views.ProfitAndLoss) { - frappe.views.ProfitAndLoss = new ProfitAndLossView(); - } - await frappe.views.ProfitAndLoss.show(params); - }); - - frappe.router.add('report/balance-sheet', async (params) => { - if (!frappe.views.BalanceSheet) { - frappe.views.BalanceSheet = new BalanceSheetView(); - } - await frappe.views.BalanceSheet.show(params); - }); - - frappe.router.add('report/trial-balance', async (params) => { - if (!frappe.views.TrialBalance) { - frappe.views.TrialBalance = new TrialBalanceView(); - } - await frappe.views.TrialBalance.show(params); - }); - - frappe.router.add('report/sales-register', async (params) => { - if (!frappe.views.SalesRegister) { - frappe.views.SalesRegister = new SalesRegisterView(); - } - await frappe.views.SalesRegister.show(params); - }); - - frappe.router.add('report/purchase-register', async (params) => { - if (!frappe.views.PurchaseRegister) { - frappe.views.PurchaseRegister = new PurchaseRegisterView(); - } - await frappe.views.PurchaseRegister.show(params); - }); - - frappe.router.add('report/accounts-receivable', async (params) => { - if (!frappe.views.AccountsReceivable) { - frappe.views.AccountsReceivable = new AccountsReceivableView(); - } - await frappe.views.AccountsReceivable.show(params); - }); - - frappe.router.add('report/accounts-payable', async (params) => { - if (!frappe.views.AccountsPayable) { - frappe.views.AccountsPayable = new AccountsPayableView(); - } - await frappe.views.AccountsPayable.show(params); - }); +module.exports = { + 'General Ledger': require('./GeneralLedger/viewConfig') } - -module.exports = registerReportRoutes; diff --git a/src/App.vue b/src/App.vue index c86e2abf..b4b2eb81 100644 --- a/src/App.vue +++ b/src/App.vue @@ -33,6 +33,7 @@ export default { diff --git a/src/components/ReportFilters.vue b/src/components/ReportFilters.vue new file mode 100644 index 00000000..00acc275 --- /dev/null +++ b/src/components/ReportFilters.vue @@ -0,0 +1,43 @@ + + + diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index d65abe7a..e5468af2 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -13,8 +13,7 @@ @@ -35,9 +34,11 @@ export default { isActive(item) { if (this.$route.params.doctype) { return this.$route.params.doctype === item.label; + } else if(this.$route.params.reportName) { + return this.$route.params.reportName === item.label; } const route = item.route.slice(1); - return this.$route.params.doctype === route; + return this.$route.path === route; } } } diff --git a/src/components/controls/Autocomplete.vue b/src/components/controls/Autocomplete.vue index fe6c87e6..93616f94 100644 --- a/src/components/controls/Autocomplete.vue +++ b/src/components/controls/Autocomplete.vue @@ -44,6 +44,7 @@ export default { return li; } }); + input.addEventListener('awesomplete-select', (e) => { console.log(e);this.$emit('awesomplete-select', e)} ) }, sort() { } diff --git a/src/components/controls/Base.vue b/src/components/controls/Base.vue index 6a8e4ed0..ac0d7160 100644 --- a/src/components/controls/Base.vue +++ b/src/components/controls/Base.vue @@ -40,7 +40,7 @@ export default { }, getLabelElement(h) { return h('label', { - class: this.labelClass, + class: [this.labelClass, 'text-muted'], attrs: { for: this.id }, diff --git a/src/components/controls/Date.vue b/src/components/controls/Date.vue index 3ec72fe7..d152c830 100644 --- a/src/components/controls/Date.vue +++ b/src/components/controls/Date.vue @@ -4,8 +4,7 @@ + @on-change="emitChange"> +import frappe from 'frappejs'; +import Link from './Link'; + +export default { + extends: Link, + inject: ['dynamicLinkTarget'], + methods: { + getTarget() { + return this.dynamicLinkTarget(this.docfield.references); + } + } +} + diff --git a/src/components/controls/FrappeControl.vue b/src/components/controls/FrappeControl.vue index 4c485364..79ad619b 100644 --- a/src/components/controls/FrappeControl.vue +++ b/src/components/controls/FrappeControl.vue @@ -19,6 +19,7 @@ import Link from './Link'; import Select from './Select'; import Table from './Table'; import Text from './Text'; +import DynamicLink from './DynamicLink'; export default { props: ['docfield', 'value', 'onlyInput'], @@ -37,6 +38,7 @@ export default { Select, Table, Text, + DynamicLink, }[this.docfield.fieldtype]; } } diff --git a/src/components/controls/Link.vue b/src/components/controls/Link.vue index 8748aada..d45a81fe 100644 --- a/src/components/controls/Link.vue +++ b/src/components/controls/Link.vue @@ -8,7 +8,7 @@ export default { methods: { async getList(query) { const list = await frappe.db.getAll({ - doctype: this.docfield.target, + doctype: this.getTarget(), filters: { keywords: ["like", query] }, @@ -28,10 +28,13 @@ export default { value: d.name })) .concat({ - label: plusIcon + ' New ' + this.docfield.target, + label: plusIcon + ' New ' + this.getTarget(), value: '__newItem' }) }, + getTarget() { + return this.docfield.target; + }, sort() { return (a, b) => { if (a.value === '__newitem' || b.value === '__newitem') { diff --git a/src/main.js b/src/main.js index 3b39a985..a41e85fd 100644 --- a/src/main.js +++ b/src/main.js @@ -21,6 +21,7 @@ import FeatherIcon from './components/FeatherIcon'; import FrappeControl from './components/controls/FrappeControl'; import Button from './components/Button'; import Indicator from './components/Indicator'; +import registerReportMethods from '../reports'; frappe.init(); frappe.registerLibs(common); @@ -34,6 +35,7 @@ frappe.db.bindSocketClient(socket); frappe.registerModels(models); frappe.docs = new Observable(); frappe.getSingle('SystemSettings'); +registerReportMethods() frappe.getSingle('AccountingSettings') .then(accountingSettings => { diff --git a/src/router/index.js b/src/router/index.js index 3e2d3b9e..438c622b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,6 +2,7 @@ import Vue from 'vue' import Router from 'vue-router' import ListAndForm from '@/components/ListAndForm' import SetupWizard from '@/pages/SetupWizard/SetupWizard' +import Report from '@/components/Report' Vue.use(Router) @@ -25,13 +26,14 @@ export default new Router({ components: { setup: SetupWizard } + }, + { + path: '/report/:reportName', + name: 'Report', + component: Report, + props: true } // { - // path: '/tree/:doctype', - // name: '', - // component: '' - // }, - // { // path: '/table/:doctype', // name: '', // component: '' diff --git a/src/sidebar.js b/src/sidebar.js index d32acc56..db7b78b2 100644 --- a/src/sidebar.js +++ b/src/sidebar.js @@ -33,7 +33,7 @@ export default [ title: 'Reports', items: [ { - label: 'General Ledger', route: '#/report/general-ledger' + label: 'General Ledger', route: '#/report/General Ledger' } ] }