Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Journal export csv with custom options #1554

Merged
merged 30 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9a0e98b
Journal export csv with custom options
mbayopanda Apr 25, 2017
b50308f
force update the branch
mbayopanda Apr 27, 2017
e287caf
Fix mergin conflicts
mbayopanda Apr 27, 2017
a2b948c
Merge branch 'master' into fix_journal_export
mbayopanda Apr 27, 2017
aedf2c1
Merge branch 'master' into fix_journal_export
mbayopanda Apr 27, 2017
fddcb14
Fix mergin conflicts
mbayopanda May 2, 2017
96686b2
Fix translation missing
mbayopanda May 2, 2017
3ec8486
Merge branch 'master' into fix_journal_export
mbayopanda May 2, 2017
60704b2
Merge branch 'master' into fix_journal_export
mbayopanda May 2, 2017
49003e8
Fix mergin conflicts
mbayopanda May 3, 2017
5b3830a
Merge branch 'master' into fix_journal_export
mbayopanda May 4, 2017
4d663fd
Merge branch 'master' into fix_journal_export
mbayopanda May 4, 2017
a4fb28c
Merge branch 'master' into fix_journal_export
mbayopanda May 4, 2017
9c4be51
Journal export csv with custom options
mbayopanda Apr 25, 2017
5a0eba3
force update the branch
mbayopanda Apr 27, 2017
8081ae8
Fix translation missing
mbayopanda May 2, 2017
54341ac
Fix mergin conflict
mbayopanda May 4, 2017
9b18d21
Merge branch 'master' into fix_journal_export
mbayopanda May 5, 2017
63c1383
Fix mergin conflicts
mbayopanda May 8, 2017
a025765
fix mergin conflicts
mbayopanda May 8, 2017
e21c788
Merge branch 'master' into fix_journal_export
mbayopanda May 8, 2017
07d7e3b
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 9, 2017
31f4662
fix mergin conflicts
mbayopanda May 9, 2017
0301dcc
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 9, 2017
d2bec39
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 9, 2017
06a81eb
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 9, 2017
3d79a76
Fix and enhancements
mbayopanda May 10, 2017
45cb46f
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 10, 2017
6d47968
Update and fix mergin conflicts
mbayopanda May 12, 2017
b3f050e
Merge branch 'master' of https://github.com/IMA-WorldHealth/bhima-2.X…
mbayopanda May 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"PREVIOUS":"Previous",
"SALE_DETAILS":"Sale Details",
"SAVE_SUCCESS":"Save success",
"EXPORT_SUCCESS": "Successfully exported",
"SEARCH":"Search",
"SHOWING":"Showing",
"TRANSACTION_REVER_SUCCESS":"This transaction was reversed with success",
Expand Down Expand Up @@ -241,6 +242,14 @@
"FATHER_NAME":"Father's Name",
"FAX":"Fax",
"FEMALE":"Female",
"RECORDS":"Records (Rows)",
"FILE_NAME":"File Name",
"COLS_ALL":"All columns",
"COLS_VISIBLE":"Visible columns",
"COLS_SELECTED":"Selected columns",
"ROWS_ALL":"All records",
"ROWS_VISIBLE":"Visible records",
"ROWS_SELECTED":"Selected records",
"FINANCIAL_DETAIL":"Current balance, the posting journal is included:",
"FINANCIAL_STATUS":"Financial Status",
"FIRST_NAME":"First Name",
Expand Down
12 changes: 12 additions & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"PREVIOUS":"Précédent",
"SALE_DETAILS":"Détaille de la Facture",
"SAVE_SUCCESS":"Enregistrement avec succès",
"EXPORT_SUCCESS": "Exportation avec succes",
"SEARCH":"Recherche",
"SHOWING":"Aperçue",
"TRANSACTION_REVER_SUCCESS":"Cette transaction a été Annulée avec succès",
Expand Down Expand Up @@ -206,6 +207,9 @@
"DEBTOR_GROUP":"Groupe Débiteur",
"DEBTOR_GROUP_FORM":"Formulaire d'enregistrement de groupe débiteur",
"DEBTOR_CREDITOR":"Débiteur/Créditeur",
"DEFAULTS" : "Filtre par defaut",
"SEARCH_QUERRIES" : "Recherche",
"LIMIT":"Limite",
"DEFINE_UNTIL_DATE":"Définir une date limite",
"DESCRIPTION":"Description",
"DETAILS":"Details",
Expand Down Expand Up @@ -241,6 +245,14 @@
"FATHER_NAME":"Nom du Père",
"FAX":"Fax",
"FEMALE":"Femme",
"RECORDS":"Enregistrements (Lignes)",
"FILE_NAME":"Nom de fichier",
"COLS_ALL":"Toutes les colonnes",
"COLS_VISIBLE":"Les colonnes visibles",
"COLS_SELECTED":"Les colonnes selectionnées",
"ROWS_ALL":"Tous les enregistrements",
"ROWS_VISIBLE":"Les enregistrements visibles",
"ROWS_SELECTED":"Les enregistrements selectionnés",
"FINANCIAL_DETAIL":"Balance actuelle, journal de saisie inclue :",
"FINANCIAL_STATUS":"Situation Financière",
"FIRST_NAME":"Prenom",
Expand Down
6 changes: 3 additions & 3 deletions client/src/i18n/fr/periods.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"PERIODS" : {
"TODAY" : "Aujourd'hui",
"THIS_WEEK" : "Cette semaine",
"THIS_MONTH" : "Ce Mois",
"THIS_YEAR" : "Cette Année",
"THIS_MONTH" : "Ce mois",
"THIS_YEAR" : "Cette année",
"YESTERDAY" : "Hier",
"LAST_WEEK" : "Semaine derniére",
"LAST_WEEK" : "Semaine derniere",
"LAST_MONTH" : "Mois dernier",
"LAST_YEAR" : "Année derniére",
"ALL_TIME" : "Tout le temps",
Expand Down
2 changes: 1 addition & 1 deletion client/src/i18n/fr/posting_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"MISSING_DATES":"Date(s) manquante(s)",
"MISSING_DOCUMENT_ID":"Ligne(s) sans ID Document",
"MISSING_ENTITY":"Ligne(s) sans ID entite",
"MISSING_FISCAL_OR_PERIOD":"Annee fiscale ou periode omise",
"MISSING_FISCAL_OR_PERIOD":"Année fiscale ou periode omise",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"MULTIPLE_CANCELLING":"Annulation multiple. Cette transaction a deja été annulée",
"SINGLE_LINE_TRANSACTION":"Transaction(s) avec une ligne",
"EDIT_INVALID_ACCOUNT":"Transaction avec des comptes non valides",
Expand Down
3 changes: 2 additions & 1 deletion client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var bhima = angular.module('bhima', [
'tmh.dynamicLocale', 'ngFileUpload', 'ui.grid',
'ui.grid.selection', 'ui.grid.autoResize', 'ui.grid.resizeColumns',
'ui.grid.edit', 'ui.grid.grouping', 'ui.grid.treeView', 'ui.grid.cellNav',
'ui.grid.pagination', 'ui.grid.moveColumns', 'angularMoment', 'ngMessages',
'ui.grid.pagination', 'ui.grid.moveColumns', 'ui.grid.exporter',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... is this possible to do without the exporter service? I don't see where it is used and I hate to introduce another dependency for something we can almost already do...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but with a lot of supplementary request to the server, also if we don't use the exporter service we cannot share the client service for exporting with custom name to other modules.

The first reason of using exporter service was because the trial balance request is so complex, and using this request again and again is not useful when we don't have a lot of data at client and data are already at the client we have just to export them.

Also exporter service give us more options for exportation which are flexible and we can use them in other modules with less effort

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your analysis is correct - for the trial balance, it is more work to export a CSV from the server side.

My biggest worry with this change is that, as a developer, I do not know when to use the server-side CSV rather than the client-side CSV. It creates another question to ask during development and something else to test....

'angularMoment', 'ngMessages',
'growlNotifications', 'ngAnimate', 'ngSanitize', 'ui.select', 'ngTouch',
'ui.router.state.events',
]);
Expand Down
56 changes: 56 additions & 0 deletions client/src/js/services/grid/GridExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
angular.module('bhima.services')
.service('GridExportService', GridExportService);

GridExportService.$inject = ['$uibModal', 'util'];

function GridExportService(Modal, util) {

/**
* @constructor
*/
function GridExport(gridOptions, defaultRowKey, defaultColKey) {

this.gridOptions = gridOptions;
this.ROWS = defaultRowKey;
this.COLS = defaultColKey;

util.after(gridOptions, 'onRegisterApi', function onRegisterApi(api) {
this.api = api;
}.bind(this));
}

/**
* @method run
* @description run the export tool
*/
GridExport.prototype.run = function run() {
var gridApi = this.api;
var gridOptions = this.gridOptions;
var rows = this.ROWS;
var cols = this.COLS;

var request = {
api: gridApi,
options: gridOptions,
rows: rows,
cols: cols,
};

var params = {
templateUrl : 'modules/templates/modals/export.modal.html',
controller : 'ExportGridModalController',
controllerAs : '$ctrl',
size : 'md',
backdrop : 'static',
animation : false,
resolve : {
data : function dataProvider() { return request; },
},
};

var instance = Modal.open(params);
return instance.result;
}

return GridExport;
}
3 changes: 2 additions & 1 deletion client/src/modules/journal/journal.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
ui-grid-selection
ui-grid-cellNav
ui-grid-edit
ui-grid-grouping>
ui-grid-grouping
ui-grid-exporter>

<bh-grid-loading-indicator
loading-state="JournalCtrl.loading"
Expand Down
15 changes: 6 additions & 9 deletions client/src/modules/journal/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JournalController.$inject = [
'SessionService', 'NotifyService', 'TransactionService', 'GridEditorService',
'bhConstants', '$state', 'uiGridConstants', 'ModalService', 'LanguageService',
'AppCache', 'Store', 'uiGridGroupingConstants', 'ExportService', 'FindEntityService',
'FilterService', '$rootScope', '$filter', 'TransactionTypeService', '$translate', '$scope',
'FilterService', '$rootScope', '$filter', '$translate', 'GridExportService', 'TransactionTypeService', '$scope',
];

/**
Expand All @@ -34,14 +34,14 @@ function JournalController(Journal, Sorting, Grouping,
Filtering, Columns, Config, Session, Notify, Transactions, Editors,
bhConstants, $state, uiGridConstants, Modal, Languages, AppCache, Store,
uiGridGroupingConstants, Export, FindEntity, Filters, $rootScope, $filter,
TransactionType, $translate, $scope) {

$translate, GridExport, TransactionType, $scope) {
// Journal utilities
var sorting;
var grouping;
var filtering;
var columnConfig;
var transactions;
var exportation;

var filter = new Filters();

Expand All @@ -51,6 +51,7 @@ function JournalController(Journal, Sorting, Grouping,
// top level cache
var cache = AppCache(cacheKey + '-module');
var vm = this;

vm.filter = filter;

// number of all of the transactions in the system
Expand Down Expand Up @@ -95,6 +96,7 @@ function JournalController(Journal, Sorting, Grouping,
grouping = new Grouping(vm.gridOptions, true, 'trans_id', vm.grouped, false);
columnConfig = new Columns(vm.gridOptions, cacheKey);
transactions = new Transactions(vm.gridOptions);
exportation = new GridExport(vm.gridOptions, 'selected', 'visible');

// attaching the filtering object to the view
vm.filtering = filtering;
Expand Down Expand Up @@ -350,12 +352,7 @@ function JournalController(Journal, Sorting, Grouping,

// export data into csv file
vm.exportFile = function exportFile() {
var url = '/reports/finance/journal';
var params = formatExportParameters('csv');

if (!params) { return; }

Export.download(url, params, 'POSTING_JOURNAL.TITLE');
exportation.run();
};

function errorHandler(error) {
Expand Down
20 changes: 19 additions & 1 deletion client/src/modules/journal/modals/trialBalanceMain.body.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<!-- exportation -->
<div class="row text-right" style="margin: 5px;">
<div class="col-xs-12">
<button
id="export"
type="button"
class="btn btn-success"
ng-click="TrialBalanceMainBodyCtrl.exportGrid()">
<i class="fa fa-file-excel-o"></i>
<span translate>FORM.BUTTONS.EXPORT</span>
</button>
</div>
</div>

<div class="row" style="margin: 5px;" ng-if="TrialBalanceMainBodyCtrl.showErrorButton">
<div class="col-xs-4">
<button
Expand All @@ -20,10 +34,14 @@
id="main-grid"
ui-grid="TrialBalanceMainBodyCtrl.gridOptions"
ui-grid-auto-resize
ui-grid-grouping>
ui-grid-grouping
ui-grid-exporter>
<bh-grid-loading-indicator
loading-state="TrialBalanceMainBodyCtrl.loading"
empty-state="TrialBalanceMainBodyCtrl.gridOptions.data.length === 0"
error-state="TrialBalanceMainBodyCtrl.hasError">
</bh-grid-loading-indicator>
</div>

<span class="ui-grid-exporter-csv-link">&nbsp</span>

17 changes: 15 additions & 2 deletions client/src/modules/journal/modals/trialBalanceMain.body.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.controllers')
TrialBalanceMainBodyController.$inject = [
'SessionService', 'TrialBalanceService', 'NotifyService',
'$state', 'uiGridConstants', 'uiGridGroupingConstants', '$filter',
'AccountService',
'AccountService', 'GridExportService',
];

/**
Expand All @@ -14,7 +14,9 @@ TrialBalanceMainBodyController.$inject = [
* This controller provides a tool to view the main state of trial balance
* The main state let you post transaction into the general ledger
*/
function TrialBalanceMainBodyController(Session, TrialBalance, Notify, $state, uiGridConstants, uiGridGroupingConstants, $filter, Accounts) {
function TrialBalanceMainBodyController(Session, TrialBalance, Notify,
$state, uiGridConstants, uiGridGroupingConstants, $filter,
Accounts, GridExport) {
var vm = this;
var currencyId = Session.enterprise.currecny_id;
var $currency = $filter('currency');
Expand Down Expand Up @@ -94,6 +96,7 @@ function TrialBalanceMainBodyController(Session, TrialBalance, Notify, $state, u

vm.enterprise = Session.enterprise;
vm.dataByTrans = records;
vm.exportGrid = exportGrid;
vm.hasError = false;

vm.gridOptions = {
Expand All @@ -107,6 +110,9 @@ function TrialBalanceMainBodyController(Session, TrialBalance, Notify, $state, u
onRegisterApi : function (api) { gridApi = api; },
};


var exportation = new GridExport(vm.gridOptions, 'all', 'visible');

/**
* @function : fetchDataByAccount
* @description :
Expand Down Expand Up @@ -257,5 +263,12 @@ function TrialBalanceMainBodyController(Session, TrialBalance, Notify, $state, u
fetchDataByAccount();
}

/**
* Export to csv
*/
function exportGrid() {
exportation.run();
}

startup();
}
45 changes: 45 additions & 0 deletions client/src/modules/templates/modals/export.modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="modal-header">
<ol class="headercrumb">
<li class="title">
<i class="fa fa-file-excel-o text-success"></i> <span translate>FORM.BUTTONS.EXPORT</span>
</li>
</ol>
</div>

<div class="modal-body">

<div class="form-group">
<label translate>FORM.LABELS.FILE_NAME</label>

<input type="text" class="form-control" ng-model="$ctrl.filename" required>
</div>

<div class="form-group">
<label translate>FORM.LABELS.RECORDS</label>
<select class="form-control" ng-model="$ctrl.exportRowType"</select>
<option value='all' translate>FORM.LABELS.ROWS_ALL</option>
<option value='visible' translate>FORM.LABELS.ROWS_VISIBLE</option>
<option value='selected' translate>FORM.LABELS.ROWS_SELECTED</option>
</select>
</div>

<div class="form-group">
<label translate>FORM.LABELS.COLUMNS</label>
<select class="form-control" ng-model="$ctrl.exportColType"</select>
<option value='all' translate>FORM.LABELS.COLS_ALL</option>
<option value='visible' translate>FORM.LABELS.COLS_VISIBLE</option>
</select>
</div>

<span class="ui-grid-exporter-csv-link">&nbsp</span>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="$ctrl.dismiss()" data-method="cancel">
<span translate>FORM.BUTTONS.CANCEL</span>
</button>

<button type="button" class="btn btn-success" ng-click="$ctrl.exportGrid()" data-method="export">
<span translate>FORM.BUTTONS.EXPORT</span>
</button>
</div>
46 changes: 46 additions & 0 deletions client/src/modules/templates/modals/export.modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
angular.module('bhima.controllers')
.controller('ExportGridModalController', ExportGridModalController);

ExportGridModalController.$inject = [
'$uibModalInstance', 'uiGridConstants', '$filter',
'moment', 'bhConstants', 'data',
];

function ExportGridModalController(Instance, uiGridConstants, $filter,
moment, bhConstants, Data) {
var vm = this;

var gridOptions = Data.options || {};
var gridApi = Data.api || {};
var filename = Data.filename || 'Export ' + moment().format('YYYY-MM-DD');
var ROWS = Data.rows || 'visible';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity, I propose we always render all rows in the grid. That's how our PDFs work and it makes sense that the filters chosen will be the ones applied to the dataset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current state of the exporter is just for csv, so we render what is visible to the client with the possibility of choosing other options (selected or all). This flexibility is useful because we have some grid which has grouped data and other not, for grid which has grouped data with the option visible the service export what is visible (ex. only grouping rows in the case of posting journal with grouped rows) and the user can select other options if he want, and developers can set the default option for grid according needs.

var COLS = Data.cols || 'visible';

// bind with view
vm.exportColType = COLS;
vm.exportRowType = ROWS;

// expose to the view
vm.exportGrid = exportGrid;
vm.dismiss = Instance.dismiss;

/**
* Export to csv
*/
function exportGrid() {
var myElement = angular.element(document.querySelectorAll('.ui-grid-exporter-csv-link'));
filename = vm.filename || filename;
gridOptions.exporterCsvFilename = filename.concat('.csv');
gridOptions.exporterHeaderFilter = exporterHeaderFilter;
gridOptions.exporterOlderExcelCompatibility = true;
gridApi.exporter.csvExport(vm.exportRowType, vm.exportColType, myElement);
Instance.close(true);
}

/**
* Exporter apply header filter
*/
function exporterHeaderFilter(displayName) {
return $filter('translate')(displayName);
}
}