Skip to content

Commit

Permalink
fix ui and integration tests for cron email report
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Jul 1, 2019
1 parent 2bbd820 commit d68d383
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 52 deletions.
7 changes: 4 additions & 3 deletions client/src/i18n/en/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"EVERY_MINUTE":"Every Minutes",
"SAVE":"Save",
"SAVED_AUTO_REPORT":"Saved report for mailing",
"LAST":"Last",
"NEXT":"Next",
"LAST":"Last Send",
"NEXT":"Next Send",
"PLEASE_FILL_REPORT_FORM":"Please fill correctly the report form",
"PLEASE_FILL_CRON_FORM":"Please fill correctly the email form",
"DATES_BEHAVIOR":"Dates behaviors",
"FIXED_DATES":"Fixed dates",
"DYNAMIC_DATES":"Dynamic dates",
"EMAIL_SENT_SUCCESSFULLY":"Email sent successfully",
"SEND":"Send"
"SEND":"Send",
"DELETE":"Delete"
}
}
7 changes: 4 additions & 3 deletions client/src/i18n/fr/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"EVERY_MINUTE":"Chaque minutes",
"SAVE":"Sauvegarder",
"SAVED_AUTO_REPORT":"Rapports sauvegardés pour le mailing",
"LAST":"Dernier",
"NEXT":"Prochain",
"LAST":"Dernier envoi",
"NEXT":"Prochain envoi",
"PLEASE_FILL_REPORT_FORM":"Veuillez remplir correctement le formulaire du rapport",
"PLEASE_FILL_CRON_FORM":"Veuillez remplir correctement le formulaire des emails",
"DATES_BEHAVIOR":"Comportement des dates",
"FIXED_DATES":"Dates fixes",
"DYNAMIC_DATES":"Dates dynamiques",
"EMAIL_SENT_SUCCESSFULLY":"Email envoyé avec succès",
"SEND":"Envoyer"
"SEND":"Envoyer",
"DELETE":"Supprimer"
}
}
16 changes: 11 additions & 5 deletions client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</bh-yes-no-radios>

<div class="text-right">
<button type="submit" class="btn btn-primary" translate>
<button data-method="save-cron-report" type="submit" class="btn btn-primary" translate>
CRON.SAVE
</button>
</div>
Expand All @@ -65,13 +65,19 @@
<tr ng-repeat="item in $ctrl.list track by item.id">
<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:'dd MMMM yyyy, hh:mm' }}</span></td>
<td><span ng-if="item.next_send"><span translate>CRON.NEXT</span>: {{ item.next_send | date:'dd MMMM yyyy, hh:mm' }}</span></td>
<td><span ng-if="item.last_send"><span translate>CRON.LAST</span><br> {{ item.last_send | date:'dd MMMM yyyy, hh:mm' }}</span></td>
<td><span ng-if="item.next_send"><span translate>CRON.NEXT</span><br> {{ item.next_send | date:'dd MMMM yyyy, hh:mm' }}</span></td>
<td>
<a ng-if="!$ctrl.sendingPending" title="{{ 'CRON.SEND' | translate }}" href ng-click="$ctrl.send(item.id)"><i class="fa fa-send text-success"></i></a>
<a class="text-info" ng-if="!$ctrl.sendingPending" href ng-click="$ctrl.send(item.id)">
<i class="fa fa-send"></i> <span translate>CRON.SEND</span>
</a>
<i ng-if="$ctrl.sendingPending" class="fa fa-circle-o-notch fa-spin"></i>
</td>
<td><a href ng-click="$ctrl.remove(item.id)"><i class="fa fa-trash text-danger"></i></a></td>
<td>
<a class="text-danger" href ng-click="$ctrl.remove(item.id)">
<i class="fa fa-trash"></i> <span translate>CRON.DELETE</span>
</a>
</td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function bhCronEmailReportController(CronEmailReports, Notify, Session) {

function remove(id) {
CronEmailReports.delete(id)
.then(() => load())
.then(() => load($ctrl.reportId))
.catch(Notify.handleError);
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/js/components/bhCronSelect/bhCronSelect.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-form="CronForm" bh-entity-group-select ng-model-options="{ updateOn: 'default' }">
<div ng-form="CronForm" bh-cron-select ng-model-options="{ updateOn: 'default' }">
<div
class="form-group"
ng-class="{ 'has-error' : CronForm.$submitted && CronForm.cron_id.$invalid }">
Expand Down
1 change: 0 additions & 1 deletion server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,5 @@ exports.configure = function configure(app) {
app.get('/cron_email_reports/:id', cronEmailReport.details);
app.post('/cron_email_reports', cronEmailReport.create);
app.post('/cron_email_reports/:id', cronEmailReport.send);
app.put('/cron_email_reports/:id', cronEmailReport.update);
app.delete('/cron_email_reports/:id', cronEmailReport.remove);
};
39 changes: 13 additions & 26 deletions server/controllers/admin/cronEmailReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ function details(req, res, next) {
.done();
}

function update(req, res, next) {
const query = `
UPDATE cron_email_report SET ? WHERE id = ?;
`;
const params = req.body;
if (params.id) {
delete params.id;
}
db.exec(query, [params, req.params.id])
.then(() => res.sendStatus(204))
.catch(next)
.done();
}

function remove(req, res, next) {
const query = `
DELETE FROM cron_email_report WHERE id = ?;
Expand Down Expand Up @@ -174,7 +160,7 @@ async function launchCronEmailReportJobs() {
function createEmailReportJob(record, cb, ...params) {
const job = addJob(record.cron_value, cb, ...params);
CURRENT_JOBS.push({ id : record.id, label : record.label, job });
return updateCronEmailReportJobDates(record.id, job);
return updateCronEmailReportNextSend(record.id, job);
}

/**
Expand Down Expand Up @@ -211,6 +197,7 @@ async function sendEmailReportDocument(record) {
});

await Promise.all(mails);
await updateCronEmailReportLastSend(record.id);
debug(`(${record.label}) report sent by email to ${contacts.length} contacts`);
}
} catch (e) {
Expand Down Expand Up @@ -262,50 +249,50 @@ function addDynamicDatesOptions(cronId, hasDynamicDates, options) {
if (cronId === DAILY) {
options.dateFrom = period.day().dateFrom;
options.dateTo = period.day().dateTo;
options.custom_period_start = period.day().dateFrom;
options.custom_period_end = period.day().dateTo;
}

if (cronId === WEEKLY) {
options.dateFrom = period.week().dateFrom;
options.dateTo = period.week().dateTo;
options.custom_period_start = period.week().dateFrom;
options.custom_period_end = period.week().dateTo;
}

if (cronId === MONTHLY) {
options.dateFrom = period.month().dateFrom;
options.dateTo = period.month().dateTo;
options.custom_period_start = period.month().dateFrom;
options.custom_period_end = period.month().dateTo;
}

if (cronId === YEARLY) {
options.dateFrom = period.year().dateFrom;
options.dateTo = period.year().dateTo;
options.custom_period_start = period.year().dateFrom;
options.custom_period_end = period.year().dateTo;
}
}
return options;
}

function updateCronEmailReportJobDates(id, job) {
function updateCronEmailReportNextSend(id, job) {
const sql = `
UPDATE cron_email_report SET ? WHERE id = ?;
`;
const params = {
last_send : job.lastDate() ? job.lastDate().toDate() : null,
next_send : job.nextDate() ? job.nextDate().toDate() : null,
};
return db.exec(sql, [params, id]);
}

function updateCronEmailReportLastSend(id) {
const sql = `
UPDATE cron_email_report SET ? WHERE id = ?;
`;
const params = {
last_send : new Date(),
};
return db.exec(sql, [params, id]);
}

launchCronEmailReportJobs();

exports.list = list;
exports.details = details;
exports.update = update;
exports.remove = remove;
exports.create = create;
exports.send = send;
4 changes: 2 additions & 2 deletions server/models/bhima.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ INSERT INTO unit VALUES
(209, 'Accounts Report Multiple','TREE.REPORTS_MULTIPLE_ACCOUNTS','',144,'/modules/reports/account_report_multiple','/reports/account_report_multiple'),
(210, 'Unbalanced Invoice Payments','REPORT.UNPAID_INVOICE_PAYMENTS_REPORT.TITLE','',144,'/modules/reports/unpaid-invoice-payments','/reports/unpaid-invoice-payments'),
(211, 'Income Expenses by Month', 'REPORT.PROFIT_AND_LOSS_BY_MONTH', 'The Report of income and expenses', 144, '/modules/finance/income_expense_by_month', '/reports/income_expense_by_month'),
(212, 'Entity Management','ENTITY.MANAGEMENT','',240,'/modules/entities','/entities'),
(213, 'Stock value Report','TREE.STOCK_VALUE','',144,'/modules/reports/stock_value','/reports/stock_value'),
(214, '[OHADA] Compte de resultat','TREE.OHADA_RESULT_ACCOUNT','',144,'/modules/reports/ohada_profit_loss','/reports/ohada_profit_loss'),
(215, 'Department management','TREE.DEPARTMENT_MANAGEMENT','Department Management', 1,'/modules/department/','/departments'),
Expand Down Expand Up @@ -127,7 +126,8 @@ INSERT INTO unit VALUES
(239, 'Visits Report', 'TREE.VISITS_REPORT', 'Visits registry', 144, '/modules/reports/visit_report', '/reports/visit_report'),
(240, '[Stock] Stock Entry Report','TREE.STOCK_ENTRY_REPORT','Stock Entry Report', 144,'/modules/reports/generated/stock_entry','/reports/stock_entry'),
(241, 'Entity Folder', 'ENTITY.MANAGEMENT', 'Entity Folder', 0, '/modules/entities', '/ENTITY_FOLDER'),
(242, 'Entity Group', 'ENTITY.GROUP.TITLE', 'Entity Group', 240, '/modules/entity_group', '/entity_group');
(242, 'Entity Management','ENTITY.MANAGEMENT','',240,'/modules/entities','/entities'),
(243, 'Entity Group', 'ENTITY.GROUP.TITLE', 'Entity Group', 240, '/modules/entity_group', '/entity_group');

-- Reserved system account type
INSERT INTO `account_category` VALUES
Expand Down
12 changes: 3 additions & 9 deletions server/models/migrations/next/migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,9 @@ UPDATE unit SET path="/depots" WHERE `name`="Depot Management" AND `key`="DEPOT.
* description: entity and entity groups units
*/
INSERT INTO `unit` VALUES
(240, 'Entity Folder', 'ENTITY.MANAGEMENT', 'Entity Folder', 0, '/modules/entities', '/ENTITY_FOLDER'),
(241, 'Entity Group', 'ENTITY.GROUP.TITLE', 'Entity Group', 240, '/modules/entity_group', '/entity_group');

/*
* @author: mbayopanda
* @date: 2019-06-04
* @description: move entity management into entity folder
*/
UPDATE unit SET parent = 240 WHERE id = 12;
(240, 'Entity Folder', 'ENTITY.MANAGEMENT', 'Entity Folder', 0, '/modules/entities', '/ENTITY_FOLDER'),
(241, 'Entity Management','ENTITY.MANAGEMENT','',240,'/modules/entities','/entities'),
(242, 'Entity Group', 'ENTITY.GROUP.TITLE', 'Entity Group', 240, '/modules/entity_group', '/entity_group');

/*
* @author: mbayopanda
Expand Down
6 changes: 5 additions & 1 deletion server/models/procedures/time_period.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This procedure help to create fiscal year and fiscal year's periods
periods include period `0` and period `13`
*/

DROP PROCEDURE IF EXISTS CreateFiscalYear$$
CREATE PROCEDURE CreateFiscalYear(
IN p_enterprise_id SMALLINT(5),
IN p_previous_fiscal_year_id MEDIUMINT(8),
Expand All @@ -30,6 +31,7 @@ BEGIN
CALL CreatePeriods(fiscalYearId);
END $$

DROP PROCEDURE IF EXISTS GetPeriodRange$$
CREATE PROCEDURE GetPeriodRange(
IN fiscalYearStartDate DATE,
IN periodNumberIndex SMALLINT(5),
Expand All @@ -43,6 +45,7 @@ CREATE PROCEDURE GetPeriodRange(
SET periodEndDate = (SELECT LAST_DAY(innerDate));
END $$

DROP PROCEDURE IF EXISTS CreatePeriods$$
CREATE PROCEDURE CreatePeriods(
IN fiscalYearId MEDIUMINT(8)
)
Expand Down Expand Up @@ -108,7 +111,7 @@ END $$


DROP PROCEDURE IF EXISTS `UpdatePeriodLabels`$$
CREATE PROCEDURE `UpdatePeriodLabels`()
CREATE PROCEDURE `UpdatePeriodLabels`()
BEGIN
DECLARE _id mediumint(8) unsigned;
DECLARE _start_date DATE;
Expand Down Expand Up @@ -151,6 +154,7 @@ to get the final opening balance.
TODO - check that there are no unposted records from previous years.
*/
DROP PROCEDURE IF EXISTS CloseFiscalYear$$
CREATE PROCEDURE CloseFiscalYear(
IN fiscalYearId MEDIUMINT UNSIGNED,
IN closingAccountId INT UNSIGNED
Expand Down
9 changes: 9 additions & 0 deletions test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,15 @@ INSERT INTO entity (uuid, display_name, gender, email, phone, address, entity_ty
(HUID('00099B1D184A48DEB93D45FBD0AB3790'), 'Bruce Wayne', 'M', 'thebat@bhi.ma', '+243000000', 'Gotham City', 1),
(HUID('037AC6C6B75A4E328E9DCDE5DA22BACE'), 'Wayne Enterprise', 'o', 'thebat@bhi.ma', '+243000000', 'Gotham City', 4);

-- default entity groups
INSERT INTO entity_group (uuid, label) VALUES
(HUID('00099B1D184A48DEB93D45FBD0AB3898'), 'Developers');

-- entity group entity
INSERT INTO entity_group_entity (entity_uuid, entity_group_uuid) VALUES
(HUID('00099B1D184A48DEB93D45FBD0AB3790'), HUID('00099B1D184A48DEB93D45FBD0AB3898')),
(HUID('037AC6C6B75A4E328E9DCDE5DA22BACE'), HUID('00099B1D184A48DEB93D45FBD0AB3898'));

-- default room type
INSERT INTO room_type VALUES
(1, 'Public Room'),
Expand Down
17 changes: 17 additions & 0 deletions test/end-to-end/reports/balance_report/balance_report.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ class BalanceReportPage {
async closeBalanceReportPreview() {
await this.page.closePreview();
}

async fillReportOptions(year, month) {
await components.fiscalYearSelect.set(year);
await components.periodSelection.set(month);
await components.yesNoRadios.set('yes', 'useSeparateDebitsAndCredits');
await components.yesNoRadios.set('no', 'includeClosingBalances');
await components.yesNoRadios.set('yes', 'shouldPruneEmptyRows');
await components.yesNoRadios.set('yes', 'shouldHideTitleAccounts');
}

// save for the auto emailing
async saveCronEmailReport(title, entityGroupName, cronFrequencyName) {
await components.inpuText.set('label', title);
await components.entityGroupSelect.set(entityGroupName);
await components.cronSelect.set(cronFrequencyName);
await this.page.saveAutoMailing();
}
}

module.exports = BalanceReportPage;
11 changes: 11 additions & 0 deletions test/end-to-end/reports/balance_report/balance_report.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ describe('Balance Report', () => {
renderer : 'PDF',
};

const cron = {
title : 'Balance report 2018',
group : 'Developers',
frequency : 'Chaque mois',
};

before(async () => {
await helpers.navigate(`#!/reports/${key}`);
Page = new BalanceReportPage(key);
Expand All @@ -36,4 +42,9 @@ describe('Balance Report', () => {
it('print the previewed report', async () => {
await Page.printBalanceReport(dataset.year, dataset.month);
});

it('save report for cron task of emailing', async () => {
await Page.fillReportOptions(dataset.year, dataset.month);
await Page.saveCronEmailReport(cron.title, cron.group, cron.frequency);
});
});
6 changes: 6 additions & 0 deletions test/end-to-end/reports/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class ReportPage {
await anchor.element(by.css('[data-method="save"]')).click();
}

// save for auto mailing
async saveAutoMailing() {
const anchor = $(this.previewAnchor);
await anchor.element(by.css('[data-method="save-cron-report"]')).click();
}

// config report
async backToConfig() {
await $(this.configAnchor).click();
Expand Down
14 changes: 14 additions & 0 deletions test/end-to-end/shared/components/bhCronSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global element, by */
const FU = require('../FormUtils');

const selector = '[bh-cron-select]';

function set(cron, id) {
const locator = (id) ? by.id(id) : by.css(selector);
const target = element(locator);
return FU.uiSelect('$ctrl.id', cron, target);
}

module.exports = {
set,
};
14 changes: 14 additions & 0 deletions test/end-to-end/shared/components/bhEntityGroupSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global element, by */
const FU = require('../FormUtils');

const selector = '[bh-entity-group-select]';

function set(entityGroup, id) {
const locator = (id) ? by.id(id) : by.css(selector);
const target = element(locator);
return FU.uiSelect('$ctrl.uuid', entityGroup, target);
}

module.exports = {
set,
};
2 changes: 2 additions & 0 deletions test/end-to-end/shared/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ module.exports = {
roomSelect : require('./bhRoomSelect'),
fiscalYearPeriodSelect : require('./bhFiscalYearPeriodSelect'),
diagnosisSelect : require('./bhDiagnosisSelect'),
entityGroupSelect : require('./bhEntityGroupSelect'),
cronSelect : require('./bhCronSelect'),
};
Loading

0 comments on commit d68d383

Please sign in to comment.