diff --git a/src/api/ADempiere/reportManagement/index.ts b/src/api/ADempiere/reportManagement/index.ts index 75321a3574..49b6f58cef 100644 --- a/src/api/ADempiere/reportManagement/index.ts +++ b/src/api/ADempiere/reportManagement/index.ts @@ -139,3 +139,44 @@ export function generateReport({ } }) } + +export function getView({ + reportType, + filters, + sortBy, + pageSize, + pageToken, + printFormatId, + reportViewId, + isSummary, + // window + tableName, + recordId +}) { + return request({ + url: `/report-engine/views/${printFormatId}`, + method: 'get', + params: { + report_type: reportType, + filters, + sort_by: sortBy, + page_size: pageSize, + page_token: pageToken, + print_format_id: printFormatId, + report_view_id: reportViewId, + is_summary: isSummary, + table_name: tableName, + record_id: recordId + } + }) +} + +export function runExport({ + format = 'xlsx', + reportId +}) { + return request({ + baseURL: `/report-engine/export/${reportId}/${format}`, + method: 'post' + }) +} diff --git a/src/components/ADempiere/ReportManager/Setup/optionsReportViewer.vue b/src/components/ADempiere/ReportManager/Setup/optionsReportViewer.vue index 235605647a..990d526fec 100644 --- a/src/components/ADempiere/ReportManager/Setup/optionsReportViewer.vue +++ b/src/components/ADempiere/ReportManager/Setup/optionsReportViewer.vue @@ -87,6 +87,7 @@ > { - return store.getters.getReportOutput(root.$route.params.reportId) + return props.reportOutput }) const isShowSetupReport = computed(() => { return store.getters.getShowPanelConfig({ containerUuid: props.containerUuid }) }) + const containerManagerReportViwer = computed(() => { const modalDialogStored = storedPanelReport.value if (!isEmptyValue(modalDialogStored) && !isEmptyValue(modalDialogStored.containerManager)) { @@ -402,14 +408,14 @@ export default defineComponent({ } function defaultReport(report) { - const { reportViewId, printFormatId, reportType } = report - reportAsViewValue.value = reportViewId - reportAsPrintFormatValue.value = printFormatId + const { report_view_id, print_format_id, reportType } = report + reportAsViewValue.value = report_view_id + reportAsPrintFormatValue.value = print_format_id reportTypeFormatValue.value = reportType store.commit('setReportGenerated', { containerUuid: props.containerUuid, - reportViewId, - printFormatId, + reportViewId: report_view_id, + printFormatId: print_format_id, reportType }) } @@ -418,9 +424,9 @@ export default defineComponent({ store.dispatch('setReportDefaultValues', { containerUuid: props.containerUuid }) - const { reportViewId, printFormatId, reportType } = defaultParams.value - reportAsViewValue.value = reportViewId - reportAsPrintFormatValue.value = printFormatId + const { report_view_id, print_format_id, reportType } = defaultParams.value + reportAsViewValue.value = report_view_id + reportAsPrintFormatValue.value = print_format_id reportTypeFormatValue.value = reportType } diff --git a/src/store/modules/ADempiere/reportManager.js b/src/store/modules/ADempiere/reportManager.js index c2e18e6161..8b4a6203b2 100644 --- a/src/store/modules/ADempiere/reportManager.js +++ b/src/store/modules/ADempiere/reportManager.js @@ -22,16 +22,22 @@ import router from '@/router' import language from '@/lang' // API Request Methods -import { generateReport, generateReportRequest, getReportOutputRequest } from '@/api/ADempiere/reportManagement/index.ts' +import { + getView, + runExport, + generateReport, + generateReportRequest, + getReportOutputRequest +} from '@/api/ADempiere/reportManagement/index.ts' import { listPrintFormatsRequest } from '@/api/ADempiere/reportManagement/printFormat.ts' import { listReportViewsRequest } from '@/api/ADempiere/reportManagement/reportView.ts' import { listDrillTablesRequest } from '@/api/ADempiere/reportManagement/drillTable.ts' // Constants import { - // REPORT_VIEWER_SUPPORTED_FORMATS, DEFAULT_REPORT_TYPE } from '@/utils/ADempiere/dictionary/report.js' +import { config } from '@/utils/ADempiere/config' // Utils and Helper Methods import { getToken } from '@/utils/auth' @@ -470,6 +476,9 @@ const reportManager = { reportType, isSummary, action, + pageToken, + pageSize, + sortBy, parametersList = [] }) { const currentRoute = router.app._route @@ -507,65 +516,75 @@ const reportManager = { reportName = action.name } - // if (isEmptyValue(instanceUuid)) { - dispatch('startReport', { - containerUuid, - reportType, - printFormatId, - reportViewId, - isSummary + if (isEmptyValue(instanceUuid)) { + dispatch('startReport', { + containerUuid, + reportType, + printFormatId, + reportViewId, + isSummary + }) + return + } + + return new Promise((resolve, reject) => { + const reportDefinition = getters.getStoredReport(containerUuid) + const { fieldsList } = reportDefinition + + const filters = getOperatorAndValue({ + format: 'array', + containerUuid, + fieldsList + }) + + getView({ + printFormatId, + reportViewId, + reportType, + pageToken, + isSummary, + tableName, + pageSize, + filters, + sortBy + }) + .then(reportResponse => { + const { + id, + name, + instance_id, + report_view_id + } = reportResponse + router.push({ + path: `report-viewer-engine/${id}/${instance_id}/${report_view_id}`, + name: 'Report Viewer Engine', + params: { + instanceUuid: instance_id, + name: name + instance_id, + fileName: name, + reportId: id, + reportUuid: reportDefinition.uuid, + tableName + } + }, () => {}) + commit('setPageSize', pageSize) + commit('setReportOutput', { + ...reportResponse, + containerUuid, + rowCells: reportResponse.rows, + instanceUuid: id + }) + resolve(reportResponse) + }) + .catch(error => { + showNotification({ + title: language.t('notifications.error'), + message: error.message, + type: 'error' + }) + console.warn(`Error getting Get Report: ${error.message}. Code: ${error.code}.`) + }) }) - return - // } - - // return new Promise((resolve) => { - // dispatch('getReportOutputFromServer', { - // uuid: uuid || containerUuid, - // containerUuid, - // reportType, - // reportName, - // tableName, - // printFormatId, - // parametersList, - // instanceUuid, - // reportViewId, - // isSummary - // }) - // .then(reportOutput => { - // dispatch('tagsView/updateVisitedView', { - // processUuid: uuid || containerUuid, - // instanceUuid, - // ...currentRoute, - // title: `${language.t('route.reportViewer')}: ${reportOutput.name} - ${instanceUuid}` - // }) - - // if (!isEmptyValue(reportOutput)) { - // if (isEmptyValue(parametersList)) { - // parametersList = reportOutput.parametersList - // } - // if (isEmptyValue(tableName)) { - // tableName = reportOutput.tableName - // } - // if (isEmptyValue(printFormatId) || printFormatId <= 0) { - // printFormatId = reportOutput.printFormatId - // } - // if (isEmptyValue(reportViewId) || reportViewId <= 0) { - // reportViewId = reportOutput.reportViewId - // } - // } - - // resolve(reportOutput) - // }) - // .finally(() => { - // commit('setReportGenerated', { - // containerUuid, - // parametersList, - // reportType, - // printFormatId, - // reportViewId - // }) - // }) - // }) }, /** * Get report output @@ -623,14 +642,6 @@ const reportManager = { tableName } }, () => {}) - // const rowCells = reportResponse.rows.map((row, rowIndex) => { - // const { cells, children } = row - // return { - // ...cells, - // children: children.length === 0 ? children : , - // level: rowIndex - // } - // }) commit('setPageSize', pageSize) commit('setReportOutput', { ...reportResponse, @@ -649,8 +660,41 @@ const reportManager = { console.warn(`Error getting Get Report: ${error.message}. Code: ${error.code}.`) }) }) + }, + /** + * Export Report + * @param {number} recordId + * @param {string} format + * @returns {files} + */ + exportReport({ + getters + }, { + reportId, + reportName + }) { + return new Promise(resolve => { + runExport({ + reportId + }) + .then(response => { + const { file_name } = response + const file = document.createElement('a') + file.href = `${config.adempiere.resource.url}${file_name}` + file.download = `${reportName}` // name of the file to be downloaded + file.click() + resolve(response) + }) + .catch(error => { + showNotification({ + title: language.t('notifications.error'), + message: error.message, + type: 'error' + }) + console.warn(`Error exporting report: ${error.message}. Code: ${error.code}.`) + }) + }) } - }, getters: { diff --git a/src/views/ADempiere/ReportViewerEngine/index.vue b/src/views/ADempiere/ReportViewerEngine/index.vue index 8ce448051a..d25c0137aa 100644 --- a/src/views/ADempiere/ReportViewerEngine/index.vue +++ b/src/views/ADempiere/ReportViewerEngine/index.vue @@ -47,6 +47,7 @@ :data="reportRow" :instance-uuid="storedReportOutput.instanceUuid" :container-manager="containerManager" + :report-output="storedReportOutput" :container-uuid="containerUuid" /> @@ -68,6 +69,7 @@ diff --git a/src/views/ADempiere/ReportViewerEngine/reportPanel.vue b/src/views/ADempiere/ReportViewerEngine/reportPanel.vue index 74ad6c5fff..de4d1c3ecb 100644 --- a/src/views/ADempiere/ReportViewerEngine/reportPanel.vue +++ b/src/views/ADempiere/ReportViewerEngine/reportPanel.vue @@ -19,6 +19,30 @@