2019-10-14 03:26:20 +05:30
|
|
|
<template>
|
2022-05-12 20:29:56 +05:30
|
|
|
<div class="flex flex-col w-full h-full">
|
|
|
|
<PageHeader :title="title">
|
2022-05-01 13:09:03 +05:30
|
|
|
<DropdownWithActions
|
2022-05-18 12:34:33 +05:30
|
|
|
v-for="group of groupedActions"
|
2022-06-09 15:40:09 +05:30
|
|
|
:icon="false"
|
2022-05-01 13:09:03 +05:30
|
|
|
:key="group.label"
|
|
|
|
:type="group.type"
|
|
|
|
:actions="group.actions"
|
|
|
|
class="text-xs"
|
|
|
|
>
|
2022-05-18 12:34:33 +05:30
|
|
|
{{ group.group }}
|
2022-05-01 13:09:03 +05:30
|
|
|
</DropdownWithActions>
|
2019-10-14 03:26:20 +05:30
|
|
|
</PageHeader>
|
2022-05-12 20:29:56 +05:30
|
|
|
|
|
|
|
<!-- Filters -->
|
2022-05-31 14:39:06 +05:30
|
|
|
<div v-if="report" class="grid grid-cols-5 gap-2 p-4 border-b">
|
2022-05-12 20:29:56 +05:30
|
|
|
<FormControl
|
|
|
|
v-for="field in report.filters"
|
2022-05-14 14:16:05 +05:30
|
|
|
size="small"
|
2022-05-12 20:29:56 +05:30
|
|
|
:show-label="field.fieldtype === 'Check'"
|
|
|
|
:key="field.fieldname + '-filter'"
|
|
|
|
class="bg-gray-100 rounded"
|
2022-05-16 12:24:58 +05:30
|
|
|
:class="field.fieldtype === 'Check' ? 'flex pl-2 py-1' : ''"
|
2022-05-14 14:16:05 +05:30
|
|
|
input-class="bg-transparent text-sm"
|
2022-05-12 20:29:56 +05:30
|
|
|
:df="field"
|
|
|
|
:value="report.get(field.fieldname)"
|
|
|
|
:read-only="loading"
|
|
|
|
@change="async (value) => await report.set(field.fieldname, value)"
|
|
|
|
/>
|
2019-11-20 00:44:15 +05:30
|
|
|
</div>
|
2022-05-12 20:29:56 +05:30
|
|
|
|
2022-05-13 12:19:08 +05:30
|
|
|
<!-- Report Body -->
|
2022-05-31 14:39:06 +05:30
|
|
|
<ListReport v-if="report" :report="report" class="" />
|
2019-10-14 03:26:20 +05:30
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2022-05-13 19:21:26 +05:30
|
|
|
import { computed } from '@vue/reactivity';
|
2022-05-16 00:18:57 +05:30
|
|
|
import { t } from 'fyo';
|
2022-05-12 20:29:56 +05:30
|
|
|
import { reports } from 'reports';
|
2022-04-22 16:32:03 +05:30
|
|
|
import FormControl from 'src/components/Controls/FormControl.vue';
|
2022-05-18 12:34:33 +05:30
|
|
|
import DropdownWithActions from 'src/components/DropdownWithActions.vue';
|
2022-05-12 20:29:56 +05:30
|
|
|
import PageHeader from 'src/components/PageHeader.vue';
|
2022-05-13 12:19:08 +05:30
|
|
|
import ListReport from 'src/components/Report/ListReport.vue';
|
2022-04-21 18:38:36 +05:30
|
|
|
import { fyo } from 'src/initFyo';
|
2022-06-19 01:47:19 +05:30
|
|
|
import { docsPathMap } from 'src/utils/misc';
|
|
|
|
import { docsPath } from 'src/utils/ui';
|
2022-05-12 20:29:56 +05:30
|
|
|
import { defineComponent } from 'vue';
|
2019-10-14 03:26:20 +05:30
|
|
|
|
2022-05-12 20:29:56 +05:30
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
2022-05-18 12:34:33 +05:30
|
|
|
reportClassName: String,
|
2022-05-27 12:45:07 +05:30
|
|
|
defaultFilters: {
|
|
|
|
type: String,
|
|
|
|
default: '{}',
|
|
|
|
},
|
2019-10-14 03:26:20 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-05-12 20:29:56 +05:30
|
|
|
loading: false,
|
|
|
|
report: null,
|
2019-10-14 03:26:20 +05:30
|
|
|
};
|
|
|
|
},
|
2022-05-13 19:21:26 +05:30
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
report: computed(() => this.report),
|
|
|
|
};
|
|
|
|
},
|
2022-05-18 12:34:33 +05:30
|
|
|
components: { PageHeader, FormControl, ListReport, DropdownWithActions },
|
2019-12-20 12:24:12 +05:30
|
|
|
async activated() {
|
2022-06-19 01:47:19 +05:30
|
|
|
docsPath.value = docsPathMap[this.reportClassName] ?? docsPathMap.Reports;
|
2022-05-12 20:29:56 +05:30
|
|
|
await this.setReportData();
|
2022-05-27 12:45:07 +05:30
|
|
|
|
|
|
|
const filters = JSON.parse(this.defaultFilters);
|
|
|
|
const filterKeys = Object.keys(filters);
|
|
|
|
for (const key of filterKeys) {
|
|
|
|
await this.report.set(key, filters[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filterKeys.length) {
|
2022-06-14 14:40:46 +05:30
|
|
|
await this.report.updateData();
|
2022-05-27 12:45:07 +05:30
|
|
|
}
|
|
|
|
|
2022-05-12 20:29:56 +05:30
|
|
|
if (fyo.store.isDevelopment) {
|
|
|
|
window.rep = this;
|
|
|
|
}
|
2019-10-14 03:26:20 +05:30
|
|
|
},
|
2022-06-19 01:47:19 +05:30
|
|
|
deactivated() {
|
|
|
|
docsPath.value = '';
|
|
|
|
},
|
2022-05-12 20:29:56 +05:30
|
|
|
computed: {
|
|
|
|
title() {
|
2022-05-18 12:34:33 +05:30
|
|
|
return reports[this.reportClassName]?.title ?? t`Report`;
|
|
|
|
},
|
|
|
|
groupedActions() {
|
|
|
|
const actions = this.report?.getActions() ?? [];
|
|
|
|
const actionsMap = actions.reduce((acc, ac) => {
|
|
|
|
if (!ac.group) {
|
|
|
|
ac.group = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
acc[ac.group] ??= {
|
|
|
|
group: ac.group,
|
|
|
|
label: ac.label ?? '',
|
|
|
|
type: ac.type,
|
|
|
|
actions: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
acc[ac.group].actions.push(ac);
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
return Object.values(actionsMap);
|
2019-12-03 17:15:07 +05:30
|
|
|
},
|
2022-05-12 20:29:56 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async setReportData() {
|
2022-05-18 12:34:33 +05:30
|
|
|
const Report = reports[this.reportClassName];
|
2022-05-16 00:18:57 +05:30
|
|
|
|
2022-05-12 20:29:56 +05:30
|
|
|
if (this.report === null) {
|
|
|
|
this.report = new Report(fyo);
|
2022-05-16 00:18:57 +05:30
|
|
|
await this.report.initialize();
|
2022-03-18 13:29:48 +05:30
|
|
|
}
|
2022-04-27 17:32:43 +05:30
|
|
|
|
2022-05-12 20:29:56 +05:30
|
|
|
if (!this.report.reportData.length) {
|
|
|
|
await this.report.setReportData();
|
2022-05-30 17:04:25 +05:30
|
|
|
} else if (this.report.shouldRefresh) {
|
|
|
|
await this.report.setReportData(undefined, true);
|
2022-03-02 13:00:48 +05:30
|
|
|
}
|
2021-12-16 15:56:18 +05:30
|
|
|
},
|
|
|
|
},
|
2022-05-12 20:29:56 +05:30
|
|
|
});
|
2019-10-14 03:26:20 +05:30
|
|
|
</script>
|