Skip to content

Commit

Permalink
Merge #3767
Browse files Browse the repository at this point in the history
3767: Auto email reports by using cron job r=jniles a=mbayopanda

This PR add a new feature of sending report automatically by email.

In this PR, we have :
- In the enterprise settings an option to enable or disable this feature of emailing
- Create a component to add in reports modules for having this feature on the report module
- Added this feature in : 
  - Balance Report
  - Bilan Report
  - Compte Resultat Report
  - Compte d'exploitation Report

![PCfDwQk18n](https://user-images.githubusercontent.com/5445251/59752269-f2941580-9279-11e9-8088-7c18982c973e.gif)


Co-authored-by: mbayopanda <mbayopanda@gmail.com>
Co-authored-by: Jonathan Niles <jonathanwniles@gmail.com>
  • Loading branch information
3 people committed Jul 8, 2019
2 parents ce8af95 + ada6cd6 commit 84b5af0
Show file tree
Hide file tree
Showing 70 changed files with 2,018 additions and 117 deletions.
24 changes: 24 additions & 0 deletions client/src/i18n/en/cron.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"CRON":{
"TITLE":"Cron",
"AUTO_EMAIL_REPORT":"Auto sending report by email",
"FREQUENCY":"Frequency",
"RECEIVERS":"Receivers",
"DAILY":"Daily",
"WEEKLY":"Weekly",
"MONTHLY":"Monthly",
"YEARLY":"Yearly",
"EACH_MINUTE":"Each Minute",
"SAVE":"Save",
"SAVED_AUTO_REPORT":"Saved report for mailing",
"LAST":"Last Sent",
"NEXT":"Next Send",
"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"
}
}
4 changes: 3 additions & 1 deletion client/src/i18n/en/enterprise.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"ENABLE_BARCODES_LABEL" : "Enables barcodes throughout the application",
"ENABLE_BARCODES_HELP_TEXT" : "Enable to place barcodes on most printed records and enable options to scan barcodes for document inputs.",
"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_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 allows users to configure schedules to automatically send reports to a list of email addresses."
}
}
}
17 changes: 12 additions & 5 deletions client/src/i18n/en/entity.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"ENTITY":{
"MANAGEMENT":"Entity Management",
"ADD_ENTITY":"Add Entity",
"EDIT_ENTITY":"Edit Entity",
"MANAGEMENT":"Contact Management",
"ADD_ENTITY":"Add Contact",
"EDIT_ENTITY":"Edit Contact",
"NAME":"Name",
"SEX":"Sex",
"PHONE":"Phone",
Expand All @@ -11,13 +11,20 @@
"CREATED":"Successfully created",
"SUCCESS":"Successfully Done",
"UPDATED":"Successfully Updated",
"LABEL":"Entity",
"LABEL":"Contact",
"TYPE":{
"LABEL":"Entity Type",
"LABEL":"Contact Type",
"PERSON":"Person",
"ENTERPRISE":"Enterprise",
"SERVICE":"Service",
"OFFICE":"Office"
},
"GROUP":{
"TITLE":"Contact Group Management",
"ADD":"Add Group",
"EDIT":"Edit Group",
"DELETE":"Delete Group",
"GROUP":"Entity Group"
}
}
}
2 changes: 2 additions & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@
"ACCOUNT_REFERENCE" : "Select an Account Reference",
"ACCOUNT_REFERENCE_TYPE" : "Select an Account Reference Type",
"ENTITY":"Select an entity",
"ENTITY_GROUP":"Select an entity group",
"ENTITY_TYPE":"Select an entity type",
"FREQUENCY":"Select a frequency",
"GENDER":"Select a gender",
"EMPTY": "Empty",
"EMPLOYEE": "Select an Employee",
Expand Down
24 changes: 24 additions & 0 deletions client/src/i18n/fr/cron.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"CRON":{
"TITLE":"Cron",
"AUTO_EMAIL_REPORT":"Envoi automatique de rapport par email",
"FREQUENCY":"Fréquence",
"RECEIVERS":"Recepteurs",
"DAILY":"Chaque jour",
"WEEKLY":"Chaque semaine",
"MONTHLY":"Chaque mois",
"YEARLY":"Chaque année",
"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":"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"
}
}
4 changes: 3 additions & 1 deletion client/src/i18n/fr/enterprise.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"ENABLE_BARCODES_LABEL" : "Activer les codes à barres dans l'application",
"ENABLE_BARCODES_HELP_TEXT" : "L'activation de cette fonction placera des codes à barres sur la plupart des enregistrements imprimés et activera les options permettant de numériser des codes à barres pour les entrées de document.",
"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_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 permet aux utilisateurs de configurer des planifications pour envoyer automatiquement des rapports à une liste d'adresses électroniques."
}
}
}
17 changes: 12 additions & 5 deletions client/src/i18n/fr/entity.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"ENTITY":{
"MANAGEMENT":"Gestion des entités",
"ADD_ENTITY":"Ajouter une entité",
"EDIT_ENTITY":"Modifier l'entité",
"MANAGEMENT":"Gestion des contacts",
"ADD_ENTITY":"Ajouter un contact",
"EDIT_ENTITY":"Modifier le contact",
"NAME":"Nom",
"SEX":"Sex",
"PHONE":"Téléphone",
"EMAIL":"Email",
"ADDRESS":"Adresse",
"CREATED":"Création de l'entité réussie avec succès",
"CREATED":"Création du contact réussie avec succès",
"SUCCESS":"Opération réussie avec succès",
"UPDATED":"Mise à jour réussie avec succès",
"LABEL":"Entité",
"TYPE":{
"LABEL":"Type d'entité",
"LABEL":"Type de contact",
"PERSON":"Personne",
"ENTERPRISE":"Entreprise",
"SERVICE":"Service",
"OFFICE":"Bureau"
},
"GROUP":{
"TITLE":"Gestion des groupe de contacts",
"ADD":"Ajouter un groupe",
"EDIT":"Editer le groupe",
"DELETE":"Supprimer le groupe",
"GROUP":"Groupe des contacts"
}
}
}
2 changes: 2 additions & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@
"ACCOUNT_REFERENCE" : "Sélectionner la référence des comptes",
"ACCOUNT_REFERENCE_TYPE" : "Sélectionner le type de référence des comptes",
"ENTITY":"Sélectionner une entité",
"ENTITY_GROUP":"Sélectionner un groupe d'entités",
"ENTITY_TYPE":"Sélectionner un type d'entité",
"FREQUENCY":"Sélectionner une frequence",
"GENDER":"Sélectionner un genre",
"EMPTY": "Vide",
"EMPLOYEE": "Sélectionner un Employé",
Expand Down
77 changes: 77 additions & 0 deletions client/src/js/components/bhCronEmailReport/bhCronEmailReport.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<section data-element="cron-email-report" 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)" novalidate>
<!-- label -->
<bh-input-text
key="label"
text-value="$ctrl.cron.label"
label="FORM.LABELS.LABEL"
autocomplete="off"
required="true">
</bh-input-text>

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

<!-- frequency -->
<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
label="CRON.DYNAMIC_DATES"
value="$ctrl.cron.has_dynamic_dates"
on-change-callback="$ctrl.onChangeDynamicDates(value)">
</bh-yes-no-radios>

<div class="text-right">
<button data-method="save-cron-report" type="submit" class="btn btn-primary" translate>
CRON.SAVE
</button>
</div>
</form>
</div>
</div>

<!-- table -->
<div ng-if="$ctrl.list.length" class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-clock-o"></i>
<span translate>CRON.SAVED_AUTO_REPORT</span>
</div>
<table class="table table-condensed">
<tbody>
<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><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 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 class="text-danger" href ng-click="$ctrl.remove(item.id)">
<i class="fa fa-trash"></i> <span translate>FORM.BUTTONS.DELETE</span>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</section>
113 changes: 113 additions & 0 deletions client/src/js/components/bhCronEmailReport/bhCronEmailReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
angular.module('bhima.components')
.component('bhCronEmailReport', {
templateUrl : 'js/components/bhCronEmailReport/bhCronEmailReport.html',
controller : bhCronEmailReportController,
transclude : true,
bindings : {
reportId : '@',
reportForm : '<',
reportDetails : '<',
onSelectReport : '&',
},
});

bhCronEmailReportController.$inject = [
'CronEmailReportService', 'NotifyService', 'SessionService',
];

function bhCronEmailReportController(CronEmailReports, Notify, Session) {
const $ctrl = this;

$ctrl.submit = submit;
$ctrl.remove = remove;
$ctrl.details = details;
$ctrl.send = send;

$ctrl.onSelectEntityGroup = entityGroup => {
$ctrl.cron.entity_group_uuid = entityGroup.uuid;
};

$ctrl.onSelectCron = cron => {
$ctrl.cron.cron_id = cron.id;
};

$ctrl.onChangeDynamicDates = value => {
$ctrl.cron.has_dynamic_dates = value;
};

$ctrl.$onInit = init;

function init() {
$ctrl.cron = {
report_id : $ctrl.reportId,
report_url : $ctrl.reportUrl,
has_dynamic_dates : 0,
};
$ctrl.isEmailFeatureEnabled = Session.enterprise.settings.enable_auto_email_report;
load($ctrl.reportId);
}

function load(id) {
CronEmailReports.read(null, { report_id : id })
.then(rows => {
$ctrl.list = rows;
})
.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 send(id) {
$ctrl.sendingPending = true;
CronEmailReports.send(id)
.then(() => {
$ctrl.sendingPending = false;
Notify.success('CRON.EMAIL_SENT_SUCCESSFULLY');
})
.catch(Notify.handleError)
.finally(() => {
$ctrl.sendingPending = false;
});
}

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

function submit(cronForm) {
if ($ctrl.reportForm.$invalid) {
Notify.warn('CRON.PLEASE_FILL_REPORT_FORM');
return;
}

if (cronForm.$invalid) {
return;
}

const params = {
cron : $ctrl.cron,
reportOptions : $ctrl.reportDetails,
};

CronEmailReports.create(params)
.then(() => reset(cronForm))
.then(() => init())
.catch(Notify.handleError);
}

function reset(form) {
form.CronForm.$setPristine();
form.EntityGroupForm.$setPristine();
form.textValueForm.$setPristine();
}
}
28 changes: 28 additions & 0 deletions client/src/js/components/bhCronSelect/bhCronSelect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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 }">

<label class="control-label" translate>
{{ $ctrl.label }}
</label>

<ng-transclude></ng-transclude>
<ui-select
name="cron_id"
ng-model="$ctrl.id"
on-select="$ctrl.onSelect($item)"
ng-required="$ctrl.required">
<ui-select-match placeholder="{{ 'FORM.SELECT.FREQUENCY' | translate }}">
<span>{{$select.selected.hrLabel}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="cron.id as cron in $ctrl.crons | filter: { 'hrLabel': $select.search }">
<span ng-bind-html="cron.hrLabel | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

<div class="help-block" ng-messages="CronForm.cron_id.$error" ng-show="CronForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
Loading

0 comments on commit 84b5af0

Please sign in to comment.