Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Bugfix/fix support print format (#2423)
Browse files Browse the repository at this point in the history
* Support Print Format

* Support Export Report

* Update reportPanel.vue

* Update reportManager.js
  • Loading branch information
elsiosanchez authored Jul 10, 2024
1 parent 71691cc commit c4a0537
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 79 deletions.
41 changes: 41 additions & 0 deletions src/api/ADempiere/reportManagement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
>
<el-option
v-for="(item, key) in reportTypeFormat.childs"

:key="key"
:label="item.name"
:value="item.type"
Expand Down Expand Up @@ -193,6 +194,10 @@ export default defineComponent({
isShowTitle: {
type: Boolean,
default: true
},
reportOutput: {
type: Object,
required: false
}
},

Expand Down Expand Up @@ -278,12 +283,13 @@ export default defineComponent({
})

const defaultParams = computed(() => {
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)) {
Expand Down Expand Up @@ -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
})
}
Expand All @@ -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
}

Expand Down
182 changes: 113 additions & 69 deletions src/store/modules/ADempiere/reportManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -470,6 +476,9 @@ const reportManager = {
reportType,
isSummary,
action,
pageToken,
pageSize,
sortBy,
parametersList = []
}) {
const currentRoute = router.app._route
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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: {
Expand Down
2 changes: 2 additions & 0 deletions src/views/ADempiere/ReportViewerEngine/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
:data="reportRow"
:instance-uuid="storedReportOutput.instanceUuid"
:container-manager="containerManager"
:report-output="storedReportOutput"
:container-uuid="containerUuid"
/>
</div>
Expand All @@ -68,6 +69,7 @@
<options-report
:container-uuid="storedReportOutput.containerUuid"
:container-manager="containerManager"
:report-output="storedReportOutput"
:is-show-title="false"
/>
</el-drawer>
Expand Down
Loading

0 comments on commit c4a0537

Please sign in to comment.