Skip to content

Commit

Permalink
fix translations and unit test for bhMoment
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Jul 1, 2019
1 parent e1edfba commit 8109ab7
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 99 deletions.
11 changes: 5 additions & 6 deletions client/src/i18n/en/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
"WEEKLY":"Weekly",
"MONTHLY":"Monthly",
"YEARLY":"Yearly",
"EVERY_MINUTE":"Every Minutes",
"EACH_MINUTE":"Each Minute",
"SAVE":"Save",
"SAVED_AUTO_REPORT":"Saved report for mailing",
"LAST":"Last Send",
"LAST":"Last Sent",
"NEXT":"Next Send",
"PLEASE_FILL_REPORT_FORM":"Please fill correctly the report form",
"PLEASE_FILL_CRON_FORM":"Please fill correctly the email form",
"PLEASE_FILL_REPORT_FORM":"Oops! It looks like there is an error in the report configuration form. Please fill it in correctly before saving the email configuration.",
"PLEASE_FILL_CRON_FORM":"The email form isn't filled out correctly. Please check the values and resubmit",
"DATES_BEHAVIOR":"Dates behaviors",
"FIXED_DATES":"Fixed dates",
"DYNAMIC_DATES":"Dynamic dates",
"EMAIL_SENT_SUCCESSFULLY":"Email sent successfully",
"SEND":"Send",
"DELETE":"Delete"
"SEND":"Send"
}
}
2 changes: 1 addition & 1 deletion client/src/i18n/en/enterprise.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ENABLE_AUTO_STOCK_ACCOUNTING_LABEL" : "Enables realtime stock accounting",
"ENABLE_AUTO_STOCK_ACCOUNTING_HELP_TEXT" : "Enabling this feature will write stock movement transactions into the posting journal in real time. It requires all inventory accounts to be correctly configured.",
"ENABLE_AUTO_EMAIL_REPORT_LABEL" : "Enable sending automatic reports by email",
"ENABLE_AUTO_EMAIL_REPORT_HELP_TEXT" : "Enabling this option gives access to the reporting configuration for automatic emails"
"ENABLE_AUTO_EMAIL_REPORT_HELP_TEXT" : "Enabling this option allows users to configure schedules to automatically send reports to a list of email addresses."
}
}
}
9 changes: 4 additions & 5 deletions client/src/i18n/fr/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
"WEEKLY":"Chaque semaine",
"MONTHLY":"Chaque mois",
"YEARLY":"Chaque année",
"EVERY_MINUTE":"Chaque minutes",
"EACH_MINUTE":"Chaque minute",
"SAVE":"Sauvegarder",
"SAVED_AUTO_REPORT":"Rapports sauvegardés pour le mailing",
"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",
"PLEASE_FILL_REPORT_FORM":"Oops! Il semble y avoir une erreur dans le formulaire de configuration du rapport. Veuillez le remplir correctement avant de sauvegarder la configuration du courrier électronique.",
"PLEASE_FILL_CRON_FORM":"The email form isn't filled out correctly. Please check the values and resubmit",
"DATES_BEHAVIOR":"Comportement des dates",
"FIXED_DATES":"Dates fixes",
"DYNAMIC_DATES":"Dates dynamiques",
"EMAIL_SENT_SUCCESSFULLY":"Email envoyé avec succès",
"SEND":"Envoyer",
"DELETE":"Supprimer"
"SEND":"Envoyer"
}
}
2 changes: 1 addition & 1 deletion client/src/i18n/fr/enterprise.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ENABLE_AUTO_STOCK_ACCOUNTING_LABEL" : "Activer la comptabilisation de stock en temps réel",
"ENABLE_AUTO_STOCK_ACCOUNTING_HELP_TEXT" : "L'activation de cette option va écrire automatiquement et en temps réel dans le journal toutes les transactions liées aux mouvements de stock. Les comptes des inventaires et groupes d'inventaire doivent être bien configurés au préalable",
"ENABLE_AUTO_EMAIL_REPORT_LABEL" : "Activer l'envoie des rapports automatiques par email",
"ENABLE_AUTO_EMAIL_REPORT_HELP_TEXT" : "L'activation de cette option donne accès à la configuration des rapports pour les emails automatiques"
"ENABLE_AUTO_EMAIL_REPORT_HELP_TEXT" : "L'activation de cette option permet aux utilisateurs de configurer des planifications pour envoyer automatiquement des rapports à une liste d'adresses électroniques."
}
}
}
34 changes: 13 additions & 21 deletions client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<section ng-if="$ctrl.isFeatureEnabled">
<section ng-if="$ctrl.isEmailFeatureEnabled">
<!-- form -->
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o"></i>
<span translate>CRON.AUTO_EMAIL_REPORT</span>
</div>
<div class="panel-body">
<form name="CronForm" bh-submit="$ctrl.submit(CronForm, $ctrl.reportForm)" novalidate>
<form name="CronForm" bh-submit="$ctrl.submit(CronForm)" novalidate>
<!-- label -->
<!-- <div class="form-group">
<label for="cronReportLabel" translate>FORM.LABELS.LABEL</label>
<input type="text" class="form-control" id="cronReportLabel" ng-model="$ctrl.cron.label" required>
</div> -->
<bh-input-text
key="label"
text-value="$ctrl.cron.label"
Expand All @@ -21,22 +17,18 @@
</bh-input-text>

<!-- group -->
<div class="form-group">
<bh-entity-group-select
uuid="$ctrl.cron.entity_group_uuid"
on-select-callback="$ctrl.onSelectEntityGroup(entityGroup)"
required="true">
</bh-entity-group-select>
</div>
<bh-entity-group-select
uuid="$ctrl.cron.entity_group_uuid"
on-select-callback="$ctrl.onSelectEntityGroup(entityGroup)"
required="true">
</bh-entity-group-select>

<!-- frequency -->
<div class="form-group">
<bh-cron-select
id="$ctrl.cron.cron_id"
on-select-callback="$ctrl.onSelectCron(cron)"
required="true">
</bh-cron-select>
</div>
<bh-cron-select
id="$ctrl.cron.cron_id"
on-select-callback="$ctrl.onSelectCron(cron)"
required="true">
</bh-cron-select>

<!-- dates behaviour -->
<bh-yes-no-radios
Expand Down Expand Up @@ -75,7 +67,7 @@
</td>
<td>
<a class="text-danger" href ng-click="$ctrl.remove(item.id)">
<i class="fa fa-trash"></i> <span translate>CRON.DELETE</span>
<i class="fa fa-trash"></i> <span translate>FORM.BUTTONS.DELETE</span>
</a>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ angular.module('bhima.components')
transclude : true,
bindings : {
reportId : '@',
reportUrl : '@',
reportForm : '<',
reportDetails : '<',
onSelectReport : '&',
Expand Down Expand Up @@ -44,7 +43,7 @@ function bhCronEmailReportController(CronEmailReports, Notify, Session) {
report_url : $ctrl.reportUrl,
has_dynamic_dates : 0,
};
$ctrl.isFeatureEnabled = Session.enterprise.settings.enable_auto_email_report;
$ctrl.isEmailFeatureEnabled = Session.enterprise.settings.enable_auto_email_report;
load($ctrl.reportId);
}

Expand Down Expand Up @@ -85,8 +84,8 @@ function bhCronEmailReportController(CronEmailReports, Notify, Session) {
.catch(Notify.handleError);
}

function submit(cronForm, reportForm) {
if (reportForm.$invalid) {
function submit(cronForm) {
if ($ctrl.reportForm.$invalid) {
Notify.warn('CRON.PLEASE_FILL_REPORT_FORM');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ <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"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ <h3 class="text-capitalize" translate>REPORT.OHADA.BALANCE_SHEET</h3>
<div class="col-md-6">
<bh-cron-email-report
report-id="20"
report-url="reports/finance/ohada_balance_sheet"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ <h3 class="text-capitalize" translate>REPORT.OHADA.PROFIT_LOSS</h3>
<div class="col-md-6">
<bh-cron-email-report
report-id="26"
report-url="reports/finance/ohada_profit_loss"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ <h3 class="text-capitalize" translate>TREE.OPERATING_ACCOUNT</h3>
<div class="col-md-6">
<bh-cron-email-report
report-id="15"
report-url="/reports/finance/operating"
report-form="ConfigForm"
report-details="ReportConfigCtrl.reportDetails"
on-select-report="ReportConfigCtrl.onSelectCronReport(report)">
Expand Down
8 changes: 4 additions & 4 deletions server/controllers/admin/cronEmailReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const debug = require('debug')('app');
const Cron = require('cron').CronJob;

const db = require('../../../lib/db');
const Moment = require('../../../lib/moment');
const BhMoment = require('../../../lib/bhMoment');
const FilterParser = require('../../../lib/filter');

const mailer = require('../../../lib/mailer');
Expand All @@ -20,7 +20,7 @@ function find(options = {}) {
const sql = `
SELECT
cer.id, cer.entity_group_uuid, cer.cron_id, cer.report_id,
cer.report_url, cer.params, cer.label, cer.last_send,
cer.params, cer.label, cer.last_send,
cer.next_send, cer.has_dynamic_dates,
eg.label AS entity_group_label,
c.label AS cron_label, c.value AS cron_value,
Expand All @@ -42,7 +42,7 @@ function lookup(id) {
const query = `
SELECT
cer.id, cer.entity_group_uuid, cer.cron_id, cer.report_id,
cer.report_url, cer.params, cer.label, cer.last_send,
cer.params, cer.label, cer.last_send,
cer.next_send, cer.has_dynamic_dates,
eg.label AS entity_group_label,
c.label AS cron_label, c.value AS cron_value,
Expand Down Expand Up @@ -243,7 +243,7 @@ function addDynamicDatesOptions(cronId, hasDynamicDates, options) {
const MONTHLY = 3;
const YEARLY = 4;

const period = new Moment(new Date());
const period = new BhMoment(new Date());

if (hasDynamicDates) {
if (cronId === DAILY) {
Expand Down
40 changes: 40 additions & 0 deletions server/lib/bhMoment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* this class helps to get start date and end date of a period
*/
const moment = require('moment');

class BhMoment {
constructor(date) {
this.value = moment(date);
}

day() {
return {
dateFrom : moment(this.value).startOf('day'),
dateTo : moment(this.value).endOf('day'),
};
}

week() {
return {
dateFrom : moment(this.value).startOf('week'),
dateTo : moment(this.value).endOf('week'),
};
}

month() {
return {
dateFrom : moment(this.value).startOf('month'),
dateTo : moment(this.value).endOf('month'),
};
}

year() {
return {
dateFrom : moment(this.value).startOf('year'),
dateTo : moment(this.value).endOf('year'),
};
}
}

module.exports = BhMoment;
11 changes: 2 additions & 9 deletions server/lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,13 @@ function processAttachments(attachments = []) {

// asynchronously load the file and add it as as an attachment
return fs.readFile(attach.path)
.then(file =>
new mailgun.Attachment({
filename : attach.filename,
data : file,
}));
.then(file => new mailgun.Attachment({ filename : attach.filename, data : file }));
}

debug(`#processAttachments() attach stream ${attach.filename}`);

// asynchronously load the file and add it as as an attachment
return new mailgun.Attachment({
filename : attach.filename,
data : attach.stream,
});
return new mailgun.Attachment({ filename : attach.filename, data : attach.stream });

}));
}
Expand Down
40 changes: 0 additions & 40 deletions server/lib/moment.js

This file was deleted.

2 changes: 1 addition & 1 deletion server/models/bhima.sql
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ INSERT INTO `cron` (`label`, `value`) VALUES
('CRON.WEEKLY', '0 1 * * 0'),
('CRON.MONTHLY', '0 1 30 * *'),
('CRON.YEARLY', '0 1 31 12 *'),
('CRON.EVERY_MINUTE', '* * * * *');
('CRON.EACH_MINUTE', '* * * * *');
1 change: 0 additions & 1 deletion server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,6 @@ CREATE TABLE `cron_email_report` (
`entity_group_uuid` BINARY(16) NOT NULL,
`cron_id` SMALLINT(5) NOT NULL,
`report_id` SMALLINT(5) NOT NULL,
`report_url` VARCHAR(200) NOT NULL,
`params` TEXT NULL,
`label` VARCHAR(200) NOT NULL,
`last_send` DATETIME NULL,
Expand Down
4 changes: 2 additions & 2 deletions test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SET NAMES 'utf8';
INSERT INTO `enterprise` VALUES
(1, 'Test Enterprise', 'TE', '243 81 504 0540', 'enterprise@test.org', HUID('1f162a10-9f67-4788-9eff-c1fea42fcc9b'), NULL, 2, 103, NULL, NULL);

INSERT INTO `enterprise_setting` (enterprise_id, enable_price_lock, enable_password_validation, enable_delete_records) VALUES
(1, 0, 1, 1);
INSERT INTO `enterprise_setting` (enterprise_id, enable_price_lock, enable_password_validation, enable_delete_records, enable_auto_email_report) VALUES
(1, 0, 1, 1, 1);

-- Project
INSERT INTO `project` VALUES
Expand Down
Loading

0 comments on commit 8109ab7

Please sign in to comment.