Skip to content

Commit

Permalink
load report details
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Jul 1, 2019
1 parent 46d7a34 commit c8c9115
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
<table class="table table-condensed">
<tbody>
<tr ng-repeat="item in $ctrl.list track by item.id">
<td>Report Label</td>
<td>Recipient <i>(Monthly)</i></td>
<td><span translate>CRON.LAST</span>: 10:34</td>
<td><span translate>CRON.NEXT</span>: 12:23</td>
<td><i class="fa fa-trash text-danger"></i></td>
<td><span class="text-action" ng-click="$ctrl.details(item.id)">{{ item.label}}</span></td>
<td><a ui-sref="entityGroup">{{ item.entity_group_label }}</a> <i>(<span translate>{{ item.cron_label }}</span>)</i></td>
<td><span ng-if="item.last_send"><span translate>CRON.LAST</span>: {{ item.last_send | date }}</span></td>
<td><span ng-if="item.next_send"><span translate>CRON.NEXT</span>: {{ item.next_send | date }}</span></td>
<td><a href ng-click="$ctrl.remove(item.id)"><i class="fa fa-trash text-danger"></i></a></td>
</tr>
</tbody>
</table>
Expand Down
33 changes: 30 additions & 3 deletions client/src/js/components/bhCronEmailReport/bhCronEmailReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ angular.module('bhima.components')
controller : bhCronEmailReportController,
transclude : true,
bindings : {
reportId : '<',
reportForm : '<',
reportDetails : '<',
reportId : '@',
reportUrl : '@',
reportForm : '<',
reportDetails : '<',
onSelectReport : '&',
},
});

Expand All @@ -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;
Expand All @@ -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 => {
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ <h3 class="text-capitalize" translate>REPORT.BALANCE_REPORT.TITLE</h3>

<div class="col-md-6">
<bh-cron-email-report
report-id="4"
report-url="/reports/finance/balance"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails">
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
</bh-cron-email-report>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions server/controllers/admin/cronEmailReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
})
Expand Down

0 comments on commit c8c9115

Please sign in to comment.