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

Commit

Permalink
Fix: Store Independent Report Engine (#2564)
Browse files Browse the repository at this point in the history
* Fix: Store Independent Report Engine

* Fix: Store Independent Report Engine

* Update notificationManager.js
  • Loading branch information
Ricargame authored Aug 8, 2024
1 parent a47bc5e commit 5d82263
Show file tree
Hide file tree
Showing 3 changed files with 517 additions and 0 deletions.
122 changes: 122 additions & 0 deletions src/store/modules/ADempiere/notificationManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
* Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* Contributor(s): Edwin Betancourt [email protected] https://github.com/EdwinBetanc0urt
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import language from '@/lang'
import {
sendNotification,
listNotificationsTypes,
listUsers
} from '@/api/ADempiere/reportManagement/index.ts'
import { showNotification } from '@/utils/ADempiere/notification.js'

const initState = {
userList: {},
notifyList: {}
}

const notifyManager = {
state: initState,
mutations: {
setNotifyList(state, notifyList) {
state.notifyList = notifyList
},
setUserList(state, userList) {
state.userList = userList
}
},
action: {
notifyUser({ commit }) {
return new Promise(resolve => {
listUsers()
.then(response => {
commit('setUserList', response)
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}.`)
})
})
},
notifyType({ commit }) {
return new Promise(resolve => {
listNotificationsTypes()
.then(response => {
commit('setNotifyList', response)
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}.`)
})
})
},
notifyReport({ commit }, {
user_id,
title,
recipients,
notification_type,
attachments,
subject
}) {
return new Promise(resolve => {
sendNotification({
user_id,
title,
recipients,
notification_type,
attachments,
subject
})
.then(response => {
showNotification({
title: language.t('notifications.succesful'),
message: title,
type: 'success'
})
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: {
getNotifyList: (state) => {
return state.notifyList
},
getUserList: (state) => {
return state.userList
}
}
}

export default notifyManager
120 changes: 120 additions & 0 deletions src/store/modules/ADempiere/report/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
* Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* Contributor(s): Edwin Betancourt [email protected] https://github.com/EdwinBetanc0urt
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import Vue from 'vue'

// Api Reqest Methods
import {
getReportOutputRequest
} from '@/api/ADempiere/reportManagement/index.ts'

// Utils and Helper Methods
import {
buildLinkHref
} from '@/utils/ADempiere/resource.js'
import { isEmptyValue } from '@/utils/ADempiere'
const initState = {
reportsOutput: {}
}

const reportManager = {
state: initState,
mutations: {
setReportOutput(state, reportOutput) {
Vue.set(state.reportsOutput, reportOutput.instanceUuid, reportOutput)
}
},
actions: {
getReportOutputFromServer({ commit, getters, rootGetters }, {
uuid,
id,
instanceUuid,
tableName,
printFormatId,
reportViewId,
isSummary,
reportName,
reportType,
parametersList = []
}) {
return new Promise(resolve => {
if (isEmptyValue(printFormatId) || printFormatId <= 0) {
const printFormat = getters.getDefaultPrintFormat(uuid)
if (!isEmptyValue(printFormat)) {
printFormatId = printFormat.printFormatId
}
}
if (isEmptyValue(parametersList)) {
parametersList = rootGetters.getParametersToServer({
containerUuid: uuid
})
}
getReportOutputRequest({
processUuid: uuid,
parametersList,
printFormatId,
reportViewId,
isSummary,
reportName,
reportType,
tableName
})
.then(response => {
let link = {
href: undefined,
download: undefined
}
if (response && response.output_stream) {
link = buildLinkHref({
fileName: response.file_name,
outputStream: response.output_stream,
type: response.mime_type
})
}

const reportOutput = {
...response,
reportId: id,
reportUuid: uuid,
isError: false,
instanceUuid,
isReport: true,
link,
parametersList,
url: link.href,
download: link.download
}

commit('setReportOutput', reportOutput)

resolve(reportOutput)
})
.catch(error => {
console.warn(`Error getting report output: ${error.message}. Code: ${error.code}.`)
})
})
}
},
getters: {
getReportOutput: (state) => (instanceUuid) => {
return state.reportsOutput[instanceUuid]
}
}
}

export default reportManager
Loading

0 comments on commit 5d82263

Please sign in to comment.