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

CDR Peremption Reporting Tool #5558

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
29 changes: 29 additions & 0 deletions client/src/i18n/en/cdr_reporting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"CDR_REPORTING" : {
"MODULE_TITLE" : "CDR Reporting",
"DATABASE_INFO" : "The following files come from the updated APISOFT database of the CDR concerned",
"DATABASE" : "Database Version",
"DEPOT" : "CDR Depots",
"DEPOT_LABEL" : "Depot (CDR)",
"REGISTRY" : "CDR Registry",
"PEREMPTION" : "CDR Peremption Rate",
"MOVEMENT_DATABASE" : "Movements File (MouvementStock.xls)",
"ARTICLE_DATABASE" : "Articles File (Article.xls)",
"LOT_DATABASE" : "Lots File (ArticleLot.xls)",
"LOT_IN_DOC_DATABASE" : "Lots in documents file (LigneLotDansDoc.xls)",
"NO_MOVEMENT_FILE_SELECTED" : "No movements file selected",
"NO_ARTICLE_FILE_SELECTED" : "No articles file selected",
"NO_LOT_FILE_SELECTED" : "No lots file selected",
"NO_LOT_DOC_FILE_SELECTED" : "No documented lots file selected",
"NO_FILE_SELECTED" : "No file selected",
"REQUIRE_FOUR_DB_FILES" : "Please select these four files : MouvementStock.xls, Article.xls, ArticleLot.xls et LigneLotDansDoc.xls",
"SHOW_PEREMPTION_REPORT" : "Show peremption report",
"UPDATE_DEPOT_DATABASE" : "Update the database",
"YEAR" : "Year",
"MONTHLY_PEREMPTION_RATE" : "Monthly peremption rate",
"TRIMONTHLY_PEREMPTION_RATE" : "Quarterly peremption rate",
"SIXMONTHLY_PEREMPTION_RATE" : "Semi annual peremption rate",
"RECOMPUTE" : "Recompute",
"DOWNLOAD" : "Download"
}
}
30 changes: 30 additions & 0 deletions client/src/i18n/fr/cdr_reporting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"CDR_REPORTING" : {
"MODULE_TITLE" : "Rapport CDR",
"DATABASE_INFO" : "Les fichiers suivant proviennent de la base de données APISOFT actualisée de la CDR concernée",
"DATABASE" : "Version de la base de données",
"DEPOT" : "CDR Depots",
"DEPOT_LABEL" : "Dépôt (CDR)",
"REGISTRY" : "CDR Registre",
"PEREMPTION" : "CDR Taux de péremption",
"MOVEMENT_DATABASE" : "Fichier des mouvements (MouvementStock.xls)",
"ARTICLE_DATABASE" : "Fichier des articles (Article.xls)",
"LOT_DATABASE" : "Fichier des lots (ArticleLot.xls)",
"LOT_IN_DOC_DATABASE" : "Fichier des lots documentés (LigneLotDansDoc.xls)",
"NO_MOVEMENT_FILE_SELECTED" : "Aucun fichier des mouvements de stock selectionné",
"NO_ARTICLE_FILE_SELECTED" : "Aucun fichier des articles selectionné",
"NO_LOT_FILE_SELECTED" : "Aucun fichier des lots en stock selectionné",
"NO_LOT_DOC_FILE_SELECTED" : "Aucun fichier des lots documentés selectionné",
"NO_FILE_SELECTED" : "Aucun fichier selectionné",
"REQUIRE_FOUR_DB_FILES" : "Veuillez selectionner les quatres fichiers suivant : MouvementStock.xls, Article.xls, ArticleLot.xls et LigneLotDansDoc.xls",
"SHOW_PEREMPTION_REPORT" : "Afficher le rapport des peremptions",
"UPDATE_DEPOT_DATABASE" : "Mettre à jour la base de données",
"YEAR" : "Année",
"PEREMPTION_REPORT_TITLE" : "Rapport sur le taux de péremption",
"MONTHLY_PEREMPTION_RATE" : "Taux de peremption mensuel",
"TRIMONTHLY_PEREMPTION_RATE" : "Taux de peremption trimestriel",
"SIXMONTHLY_PEREMPTION_RATE" : "Taux de peremption semestriel",
"RECOMPUTE" : "Recalculer",
"DOWNLOAD" : "Télécharger"
}
}
46 changes: 46 additions & 0 deletions client/src/modules/cdr_reporting/cdr_reporting.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
angular.module('bhima.routes')
.config(['$stateProvider', $stateProvider => {
$stateProvider
.state('cdrReportingDepots', {
url : '/cdr_reporting/depots',
controller : 'CDRReportingDepotController as CdrDepotCtrl',
templateUrl : 'modules/cdr_reporting/depots/depots.html',
})

.state('cdrReportingDepots.create', {
url : '/create',
params : {
isCreateState : { value : true },
},
onEnter : ['$uibModal', '$transition$', cdrDepotModal],
onExit : ['$uibModalStack', closeModal],
})

.state('cdrReportingDepots.edit', {
url : '/:uuid/edit',
params : {
uuid : { value : null, squash : true },
isCreateState : { value : false },
},
onEnter : ['$uibModal', '$transition$', cdrDepotModal],
onExit : ['$uibModalStack', closeModal],
})

.state('cdrReportingPeremptionRate', {
url : '/cdr_reporting/peremption',
controller : 'CDRReportingPeremptionRateController as CdrPeremptionRateCtrl',
templateUrl : 'modules/cdr_reporting/peremption/peremption.html',
});
}]);

function cdrDepotModal($modal, $transition) {
$modal.open({
templateUrl : 'modules/cdr_reporting/depots/modals/depot.modal.html',
controller : 'CdrDepotModalController as CdrDepotModalCtrl',
resolve : { params : () => $transition.params('to') },
}).result.catch(angular.noop);
}

function closeModal(ModalStack) {
ModalStack.dismissAll();
}
59 changes: 59 additions & 0 deletions client/src/modules/cdr_reporting/cdr_reporting.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
angular.module('bhima.services')
.service('CdrDepotService', CdrDepotService);

CdrDepotService.$inject = ['PrototypeApiService', 'LanguageService'];

/**
* @class DepotService
* @extends PrototypeApiService
*
* @description
* Encapsulates common requests to the /depots/ URL.
*/
function CdrDepotService(Api, Languages) {
const baseUrl = '/cdr_reporting/depots/';
const service = new Api(baseUrl);

service.getAvailableYears = () => {
const target = baseUrl.concat('available_years');
return service.$http.get(target)
.then(service.util.unwrapHttpResponse);
};

service.getPeremptionReport = (params) => {
const options = {
renderer : 'html',
lang : Languages.key,
year : params.year,
recompute : params.recompute,
};
const target = baseUrl.concat('peremption');
return service.$http.get(target, { params : options })
.then(service.util.unwrapHttpResponse);
};

service.downloadReport = (year) => {
const responseType = 'arraybuffer';
const pdfType = 'application/pdf';
const options = {
renderer : 'pdf',
lang : Languages.key,
year,
};
const target = baseUrl.concat('peremption/download');
return service.$http.get(target, { params : options, responseType })
.then((result) => {
const file = new Blob([result.data], { type : pdfType });
const fileURL = URL.createObjectURL(file);

const fileName = `Rapport taux de peremption - ${year}.pdf`;
const a = document.createElement('a');
document.body.appendChild(a);
a.href = fileURL;
a.download = fileName;
a.click();
});
};

return service;
}
37 changes: 37 additions & 0 deletions client/src/modules/cdr_reporting/depots/depots.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="flex-header">
<div class="bhima-title">
<ol class="headercrumb">
<li class="static" translate> CDR_REPORTING.MODULE_TITLE </li>
<li class="title" translate> CDR_REPORTING.DEPOT </li>
</ol>

<div class="toolbar">
<div class="toolbar-item">
<button class="btn btn-default text-capitalize" id="create" ng-click="CdrDepotCtrl.createDepot()" data-method="create">
<span class="fa fa-plus"></span> <span translate>DEPOT.ADD_DEPOT</span>
</button>
</div>
<bh-filter-toggle on-toggle="CdrDepotCtrl.toggleFilter()"></bh-filter-toggle>
</div>
</div>
</div>

<!-- main content -->
<div class="flex-content">
<div class="container-fluid">
<div
id="cdr-depot-grid"
ui-grid="CdrDepotCtrl.gridOptions"
class="grid-full-height"
ui-grid-auto-resize
ui-grid-resize-columns>

<bh-grid-loading-indicator
loading-state="CdrDepotCtrl.loading"
empty-state="CdrDepotCtrl.gridOptions.data.length === 0"
error-state="CdrDepotCtrl.hasError">
</bh-grid-loading-indicator>
</div>
</div>
</div>

125 changes: 125 additions & 0 deletions client/src/modules/cdr_reporting/depots/depots.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
angular.module('bhima.controllers')
.controller('CDRReportingDepotController', CDRReportingDepotController);

CDRReportingDepotController.$inject = [
'CdrDepotService', 'ModalService', 'NotifyService', 'uiGridConstants', '$state',
];

function CDRReportingDepotController(
Depots, ModalService, Notify, uiGridConstants, $state,
) {
const vm = this;

// bind methods
vm.deleteDepot = deleteDepot;
vm.editDepot = editDepot;
vm.createDepot = createDepot;
vm.toggleFilter = toggleFilter;
vm.showPeremptionReport = showPeremptionReport;

// global variables
vm.gridApi = {};

// options for the UI grid
vm.gridOptions = {
appScopeProvider : vm,
enableColumnMenus : false,
showColumnFooter : true,
fastWatch : true,
flatEntityAccess : true,
enableSorting : true,
showTreeExpandNoChildren : false,
onRegisterApi : onRegisterApiFn,
columnDefs : [
{
field : 'text',
displayName : 'CDR_REPORTING.DEPOT_LABEL',
headerCellFilter : 'translate',
cellTemplate : '/modules/cdr_reporting/depots/templates/label.tmpl.html',
aggregationType : uiGridConstants.aggregationTypes.count,
aggregationHideLabel : true,
},
{
field : 'last_movement_date',
displayName : 'CDR_REPORTING.DATABASE',
headerCellFilter : 'translate',
cellTemplate : '/modules/cdr_reporting/depots/templates/version.tmpl.html',
},
{
field : 'action',
width : 80,
displayName : '',
cellTemplate : '/modules/cdr_reporting/depots/templates/action.tmpl.html',
enableSorting : false,
enableFiltering : false,
},
],
};

function onRegisterApiFn(gridApi) {
vm.gridApi = gridApi;
}

function toggleFilter() {
vm.gridOptions.enableFiltering = !vm.gridOptions.enableFiltering;
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
}

function load() {
vm.loading = true;

Depots.read()
.then(data => {
vm.gridOptions.data = data.map(item => {
item.last_movement_date = new Date(item.last_movement_date);
return item;
});
})
.catch(Notify.handleError)
.finally(() => {
vm.loading = false;
});
}

function showPeremptionReport(uuid) {
const current = new Date();
const params = {
uuid,
year : current.getFullYear(),
recompute : 1,
};
$state.go('cdrReportingPeremptionRate', params);
}

// switch to delete warning mode
function deleteDepot(uuid) {
ModalService.confirm('FORM.DIALOGS.CONFIRM_DELETE')
.then(bool => {
if (!bool) { return; }

Depots.delete(uuid)
.then(() => {
Notify.success('DEPOT.DELETED');
load();
})
.catch(Notify.handleError);
});
}

// update an existing depot
function editDepot(uuid) {
$state.go('cdrReportingDepots.edit', { uuid });
}

// create a new depot
function createDepot() {
$state.go('cdrReportingDepots.create');
}

// initialize module
function startup() {
load();
}

startup();
}
Loading