2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: Reports

- Filters
- Set default filters
- Horizontal and Vertical scroll (wip)
This commit is contained in:
Faris Ansari 2019-11-20 00:44:15 +05:30
parent c36d50086f
commit 259f22df09
6 changed files with 111 additions and 27 deletions

View File

@ -1,3 +1,5 @@
const frappe = require('frappejs');
module.exports = { module.exports = {
title: 'Balance Sheet', title: 'Balance Sheet',
method: 'balance-sheet', method: 'balance-sheet',
@ -8,7 +10,10 @@ module.exports = {
size: 'small', size: 'small',
placeholder: 'ToDate', placeholder: 'ToDate',
label: 'To Date', label: 'To Date',
required: 1 required: 1,
default: async () => {
return (await frappe.getSingle('AccountingSettings')).fiscalYearEnd;
}
}, },
{ {
fieldtype: 'Select', fieldtype: 'Select',

View File

@ -2,8 +2,6 @@ const frappe = require('frappejs');
class GeneralLedger { class GeneralLedger {
async run(params) { async run(params) {
if (!Object.keys(params).length) return [];
const filters = {}; const filters = {};
if (params.account) filters.account = params.account; if (params.account) filters.account = params.account;
if (params.party) filters.party = params.party; if (params.party) filters.party = params.party;
@ -39,7 +37,7 @@ class GeneralLedger {
glEntries.push({ glEntries.push({
date: '', date: '',
account: '<b>Opening</b>', account: { template: '<b>Opening</b>' },
party: '', party: '',
debit: 0, debit: 0,
credit: 0, credit: 0,
@ -56,7 +54,7 @@ class GeneralLedger {
} }
glEntries.push({ glEntries.push({
date: '', date: '',
account: '<b>Total</b>', account: { template: '<b>Total</b>' },
party: '', party: '',
debit: debitTotal, debit: debitTotal,
credit: creditTotal, credit: creditTotal,
@ -66,7 +64,7 @@ class GeneralLedger {
}); });
glEntries.push({ glEntries.push({
date: '', date: '',
account: '<b>Closing</b>', account: { template: '<b>Closing</b>' },
party: '', party: '',
debit: debitTotal, debit: debitTotal,
credit: creditTotal, credit: creditTotal,

View File

@ -5,10 +5,16 @@ const viewConfig = {
filterFields: [ filterFields: [
{ {
fieldtype: 'Select', fieldtype: 'Select',
options: ['Select...', 'SalesInvoice', 'Payment', 'PurchaseInvoice'], options: [
{ label: '', value: '' },
{ label: 'Sales Invoice', value: 'SalesInvoice' },
{ label: 'Payment', value: 'Payment' },
{ label: 'Purchase Invoice', value: 'PurchaseInvoice' }
],
size: 'small', size: 'small',
label: 'Reference Type', label: 'Reference Type',
fieldname: 'referenceType' fieldname: 'referenceType',
placeholder: 'Reference Type'
}, },
{ {
fieldtype: 'DynamicLink', fieldtype: 'DynamicLink',

View File

@ -1,3 +1,5 @@
const frappe = require('frappejs');
const title = 'Profit and Loss'; const title = 'Profit and Loss';
module.exports = { module.exports = {
title: title, title: title,
@ -10,7 +12,10 @@ module.exports = {
size: 'small', size: 'small',
placeholder: 'From Date', placeholder: 'From Date',
label: 'From Date', label: 'From Date',
required: 1 required: 1,
default: async () => {
return (await frappe.getSingle('AccountingSettings')).fiscalYearStart;
}
}, },
{ {
fieldtype: 'Date', fieldtype: 'Date',
@ -18,7 +23,10 @@ module.exports = {
size: 'small', size: 'small',
placeholder: 'To Date', placeholder: 'To Date',
label: 'To Date', label: 'To Date',
required: 1 required: 1,
default: async () => {
return (await frappe.getSingle('AccountingSettings')).fiscalYearEnd;
}
}, },
{ {
fieldtype: 'Select', fieldtype: 'Select',
@ -30,6 +38,7 @@ module.exports = {
'Half Yearly', 'Half Yearly',
'Yearly' 'Yearly'
], ],
default: 'Monthly',
label: 'Periodicity', label: 'Periodicity',
fieldname: 'periodicity' fieldname: 'periodicity'
} }

View File

@ -1,3 +1,5 @@
const frappe = require('frappejs');
const title = 'Trial Balance'; const title = 'Trial Balance';
module.exports = { module.exports = {
title: title, title: title,
@ -10,7 +12,10 @@ module.exports = {
label: 'From Date', label: 'From Date',
size: 'small', size: 'small',
placeholder: 'From Date', placeholder: 'From Date',
required: 1 required: 1,
default: async () => {
return (await frappe.getSingle('AccountingSettings')).fiscalYearStart;
}
}, },
{ {
fieldtype: 'Date', fieldtype: 'Date',
@ -18,7 +23,10 @@ module.exports = {
placeholder: 'To Date', placeholder: 'To Date',
fieldname: 'toDate', fieldname: 'toDate',
label: 'To Date', label: 'To Date',
required: 1 required: 1,
default: async () => {
return (await frappe.getSingle('AccountingSettings')).fiscalYearEnd;
}
} }
], ],
linkFields: [ linkFields: [

View File

@ -1,19 +1,39 @@
<template> <template>
<div class="flex flex-col max-w-full"> <div class="flex flex-col max-w-full">
<PageHeader> <PageHeader>
<h1 slot="title" class="text-xl font-bold">{{ report.title }}</h1> <h1 slot="title" class="text-2xl font-bold">{{ report.title }}</h1>
<template slot="actions"> <template slot="actions">
<SearchBar class="ml-2" /> <SearchBar class="ml-2" />
</template> </template>
</PageHeader> </PageHeader>
<div class="mt-6 flex text-base px-8" v-if="report.filterFields">
<div class="ml-3 first:ml-0 w-32" v-for="df in report.filterFields">
<FormControl
input-class="bg-gray-100"
size="small"
:df="df"
:value="filters[df.fieldname]"
@change="value => onFilterChange(df, value)"
:target="
df.fieldtype === 'DynamicLink' ? filters[df.references] : null
"
/>
</div>
</div>
<div class="px-8 mt-4"> <div class="px-8 mt-4">
<div class="overflow-auto" :style="{height: 'calc(100vh - 6rem)'}"> <div class="overflow-auto" :style="{ height: 'calc(100vh - 8rem)' }">
<Row :columnCount="columns.length" gap="1rem" column-width="minmax(200px, 1fr)"> <Row
:columnCount="columns.length"
gap="1rem"
column-width="minmax(200px, 1fr)"
>
<div <div
class="text-gray-600 text-sm truncate py-4" class="text-gray-600 text-base truncate py-4"
v-for="column in columns" v-for="column in columns"
:key="column.label" :key="column.label"
>{{ column.label }}</div> >
{{ column.label }}
</div>
</Row> </Row>
<div class="flex-1"> <div class="flex-1">
<Row <Row
@ -24,11 +44,18 @@
column-width="minmax(200px, 1fr)" column-width="minmax(200px, 1fr)"
> >
<div <div
class="text-gray-900 text-sm truncate py-4" class="text-gray-900 text-base truncate py-4"
v-for="column in columns" v-for="column in columns"
:key="column.label" :key="column.label"
v-html="row[column.fieldname]" >
></div> <component
v-if="typeof row[column.fieldname] === 'object'"
:is="row[column.fieldname]"
/>
<template v-else>
{{ frappe.format(row[column.fieldname], column) }}
</template>
</div>
</Row> </Row>
</div> </div>
</div> </div>
@ -41,7 +68,9 @@ import PageHeader from '@/components/PageHeader';
import Button from '@/components/Button'; import Button from '@/components/Button';
import SearchBar from '@/components/SearchBar'; import SearchBar from '@/components/SearchBar';
import Row from '@/components/Row'; import Row from '@/components/Row';
import FormControl from '@/components/Controls/FormControl';
import reportViewConfig from '@/../reports/view'; import reportViewConfig from '@/../reports/view';
import throttle from 'lodash/throttle';
export default { export default {
name: 'Report', name: 'Report',
@ -50,26 +79,36 @@ export default {
PageHeader, PageHeader,
Button, Button,
SearchBar, SearchBar,
Row Row,
FormControl
},
provide() {
return {
doc: this.filters
}
}, },
data() { data() {
let filters = {};
for (let df of reportViewConfig[this.reportName].filterFields) {
filters[df.fieldname] = null;
}
return { return {
filters,
rows: [], rows: [],
columns: [] columns: []
}; };
}, },
mounted() { async mounted() {
this.columns = this.report.getColumns(); this.columns = this.report.getColumns();
this.fetchReportData(); await this.setDefaultFilters();
await this.fetchReportData();
}, },
methods: { methods: {
async fetchReportData() { async fetchReportData() {
let data = await frappe.call({ let data = await frappe.call({
method: this.report.method, method: this.report.method,
args: { args: this.filters
fromDate: '2019-09-01',
toDate: '2019-10-31'
}
}); });
let rows, columns; let rows, columns;
@ -88,6 +127,25 @@ export default {
} }
this.rows = rows; this.rows = rows;
},
onFilterChange(df, value) {
this.filters[df.fieldname] = value;
this.fetchReportData();
},
async setDefaultFilters() {
for (let df of this.report.filterFields) {
let defaultValue = null;
if (df.default) {
if (typeof df.default === 'function') {
defaultValue = await df.default();
} else {
defaultValue = df.default;
}
}
this.filters[df.fieldname] = defaultValue;
}
} }
}, },
computed: { computed: {