diff --git a/client/src/js/components/bhCronEmailReport/bhCronEmailReport.html b/client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
index f961fb1b31..6fc118a3de 100644
--- a/client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
+++ b/client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
@@ -47,11 +47,11 @@
- Report Label |
- Recipient (Monthly) |
- CRON.LAST: 10:34 |
- CRON.NEXT: 12:23 |
- |
+ {{ item.label}} |
+ {{ item.entity_group_label }} ({{ item.cron_label }}) |
+ CRON.LAST: {{ item.last_send | date }} |
+ CRON.NEXT: {{ item.next_send | date }} |
+ |
diff --git a/client/src/js/components/bhCronEmailReport/bhCronEmailReport.js b/client/src/js/components/bhCronEmailReport/bhCronEmailReport.js
index 8926c6961b..21f005ad95 100644
--- a/client/src/js/components/bhCronEmailReport/bhCronEmailReport.js
+++ b/client/src/js/components/bhCronEmailReport/bhCronEmailReport.js
@@ -4,9 +4,11 @@ angular.module('bhima.components')
controller : bhCronEmailReportController,
transclude : true,
bindings : {
- reportId : '<',
- reportForm : '<',
- reportDetails : '<',
+ reportId : '@',
+ reportUrl : '@',
+ reportForm : '<',
+ reportDetails : '<',
+ onSelectReport : '&',
},
});
@@ -18,6 +20,8 @@ function bhCronEmailReportController(CronEmailReports, Notify) {
const $ctrl = this;
$ctrl.submit = submit;
+ $ctrl.remove = remove;
+ $ctrl.details = details;
$ctrl.onSelectEntityGroup = entityGroup => {
$ctrl.cron.entity_group_uuid = entityGroup.uuid;
@@ -27,6 +31,13 @@ function bhCronEmailReportController(CronEmailReports, Notify) {
$ctrl.cron.cron_id = cron.id;
};
+ $ctrl.$onInit = () => {
+ $ctrl.cron = {
+ report_id : $ctrl.reportId,
+ report_url : $ctrl.reportUrl,
+ };
+ };
+
function load() {
CronEmailReports.read()
.then(rows => {
@@ -35,6 +46,22 @@ function bhCronEmailReportController(CronEmailReports, Notify) {
.catch(Notify.handleError);
}
+ function details(id) {
+ CronEmailReports.read(id)
+ .then(row => {
+ if (!row) { return; }
+ const report = JSON.parse(row.params);
+ $ctrl.onSelectReport({ report });
+ })
+ .catch(Notify.handleError);
+ }
+
+ function remove(id) {
+ CronEmailReports.delete(id)
+ .then(() => load())
+ .catch(Notify.handleError);
+ }
+
function submit(cronForm, reportForm) {
if (reportForm.$invalid) {
Notify.warn('CRON.PLEASE_FILL_REPORT_FORM');
diff --git a/client/src/modules/reports/generate/balance_report/balance_report.config.js b/client/src/modules/reports/generate/balance_report/balance_report.config.js
index a11b973b14..38b2df1bf7 100644
--- a/client/src/modules/reports/generate/balance_report/balance_report.config.js
+++ b/client/src/modules/reports/generate/balance_report/balance_report.config.js
@@ -41,6 +41,10 @@ function BalanceReportConfigController($sce, Notify, SavedReports, AppCache, rep
vm.reportDetails.includeClosingBalances = bool;
};
+ vm.onSelectCronReport = report => {
+ vm.reportDetails = angular.copy(report);
+ };
+
vm.preview = function preview(form) {
if (form.$invalid) {
Notify.danger('FORM.ERRORS.RECORD_ERROR');
diff --git a/client/src/modules/reports/generate/balance_report/balance_report.html b/client/src/modules/reports/generate/balance_report/balance_report.html
index 49373ee93e..62ee6894dd 100644
--- a/client/src/modules/reports/generate/balance_report/balance_report.html
+++ b/client/src/modules/reports/generate/balance_report/balance_report.html
@@ -80,8 +80,11 @@ REPORT.BALANCE_REPORT.TITLE
+ report-details="ReportConfigCtrl.reportDetails"
+ on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
diff --git a/server/controllers/admin/cronEmailReport/index.js b/server/controllers/admin/cronEmailReport/index.js
index a6e76d6d35..2d6ce1d8d8 100644
--- a/server/controllers/admin/cronEmailReport/index.js
+++ b/server/controllers/admin/cronEmailReport/index.js
@@ -73,9 +73,11 @@ function create(req, res, next) {
const query = `
INSERT INTO cron_email_report SET ?;
`;
- const params = req.body;
- console.log(params);
- db.exec(query, [params])
+ const { cron, report } = req.body;
+ db.convert(cron, ['entity_group_uuid']);
+ cron.params = JSON.stringify(report);
+
+ db.exec(query, [cron])
.then((result) => {
res.status(201).json({ id : result.insertId });
})