Skip to content

Commit

Permalink
Merge #3757
Browse files Browse the repository at this point in the history
3757: Split hospitalization indicators report by projects r=jeremielodi a=mbayopanda

This PR : 
- Link service with project by adding a new column `project_id` in service
- Split hospitalization indicators by projects in the indicators report

Co-authored-by: mbayopanda <mbayopanda@gmail.com>
  • Loading branch information
bors[bot] and mbayopanda committed Jun 3, 2019
2 parents 752723a + 200d0a7 commit fc69b92
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 111 deletions.
1 change: 1 addition & 0 deletions client/src/js/components/bhProjectSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ angular.module('bhima.components')
projectId : '<',
onSelectCallback : '&',
name : '@?',
required : '<?',
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function IndicatorsReportController($sce, Notify, SavedReports, AppCache, report
.catch(Notify.handleError);
};

vm.onSelectService = service => {
vm.reportDetails.service_id = service.id;
};

vm.clear = (key) => {
delete vm.reportDetails[key];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3 class="text-capitalize" translate>REPORT.REPORT_INDICATORS.TITLE</h3>
<!-- indicator type selection -->
<div class="form-group" ng-class="{ 'has-error' : ConfigForm.$submitted && ConfigForm.type.$invalid }">
<label class="control-label">
<i class="fa fa-briefcase"></i> <span translate> FORM.SELECT.INDICATOR_TYPE</span>
<span translate> FORM.SELECT.INDICATOR_TYPE</span>
</label>
<bh-clear on-clear="ReportConfigCtrl.clear('type')"></bh-clear>
<select
Expand All @@ -45,7 +45,13 @@ <h3 class="text-capitalize" translate>REPORT.REPORT_INDICATORS.TITLE</h3>
ng-options="type.id as (type.label | translate) for type in ReportConfigCtrl.indicatorTypes">
<option value="" disabled>{{ "FORM.SELECT.INDICATOR_TYPE" | translate }}<option>
</select>
</div>
</div>

<bh-service-select
service-id="ReportConfigCtrl.reportDetails.service_id"
on-select-callback="ReportConfigCtrl.onSelectService(service)">
<bh-clear on-clear="ReportConfigCtrl.clear('service_id')"></bh-clear>
</bh-service-select>
</bh-hidden-field>

<bh-loading-button loading-state="ConfigForm.$loading">
Expand Down
20 changes: 12 additions & 8 deletions client/src/modules/services/modals/service.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@
</div>
</div>


<!-- amortissement and depreciation -->
<bh-project-select
project-id="ServiceModalCtrl.service.project_id"
on-select-callback="ServiceModalCtrl.onSelectProject(project)"
required="true">
</bh-project-select>

<div class="form-group" ng-hide="ServiceModalCtrl.isCreating">
<div class="checkbox">
<label class="control-label">
<input name="hidden" type="checkbox" ng-model="ServiceModalCtrl.service.hidden" ng-true-value="1" ng-false-value="0">
<span translate>FORM.LABELS.HIDDEN</span>
</label>
</div>
<div class="checkbox">
<label class="control-label">
<input name="hidden" type="checkbox" ng-model="ServiceModalCtrl.service.hidden" ng-true-value="1" ng-false-value="0">
<span translate>FORM.LABELS.HIDDEN</span>
</label>
</div>
</div>

</div>

Expand Down
29 changes: 18 additions & 11 deletions client/src/modules/services/modals/service.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ ServiceModalController.$inject = [

function ServiceModalController($state, Services, Depots, $translate,
SessionService, ModalService, util, Notify) {
var vm = this;
var paramService = $state.params.service || {};

vm.service = { id : paramService.id, name : paramService.name, hidden : paramService.hidden };
const vm = this;
const paramService = $state.params.service || {};

vm.service = {
id : paramService.id,
name : paramService.name,
hidden : paramService.hidden,
project_id : paramService.project_id,
};
vm.isCreating = !!($state.params.creating);

// exposed methods
vm.submit = submit;
vm.closeModal = closeModal;

vm.onSelectProject = project => {
vm.service.project_id = project.id;
};

// submit the data to the server from all two forms (update, create)
function submit(serviceForm) {
var promise;

if (serviceForm.$invalid || !serviceForm.$dirty) { return 0; }

promise = (vm.isCreating) ?
Services.create(vm.service) :
Services.update(vm.service.id, vm.service);
const promise = (vm.isCreating)
? Services.create(vm.service)
: Services.update(vm.service.id, vm.service);

return promise
.then(function () {
var translateKey = (vm.isCreating) ? 'SERVICE.CREATED' : 'SERVICE.UPDATED';
.then(() => {
const translateKey = (vm.isCreating) ? 'SERVICE.CREATED' : 'SERVICE.UPDATED';
Notify.success(translateKey);
$state.go('services', null, { reload : true });
})
Expand Down
81 changes: 59 additions & 22 deletions client/src/modules/services/services.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
angular.module('bhima.controllers')
.controller('ServicesController', ServicesController);
.controller('ServicesController', ServicesController);

ServicesController.$inject = [
'ServiceService', 'ModalService', 'NotifyService', 'uiGridConstants', '$state',
'ServiceService', 'ModalService', 'NotifyService', 'uiGridConstants', '$state', '$timeout',
];

function ServicesController(Services, ModalService, Notify, uiGridConstants, $state) {
var vm = this;
function ServicesController(Services, ModalService, Notify, uiGridConstants, $state, $timeout) {
const vm = this;

// bind methods
vm.deleteService = deleteService;
Expand All @@ -27,8 +27,18 @@ function ServicesController(Services, ModalService, Notify, uiGridConstants, $st
enableSorting : true,
onRegisterApi : onRegisterApiFn,
columnDefs : [
{ field : 'name', displayName : 'FORM.LABELS.SERVICE', headerCellFilter : 'translate' },
{ field : 'action',
{
field : 'name',
displayName : 'FORM.LABELS.SERVICE',
headerCellFilter : 'translate',
},
{
field : 'project_name',
displayName : 'FORM.LABELS.PROJECT',
headerCellFilter : 'translate',
},
{
field : 'action',
width : 80,
displayName : '',
cellTemplate : '/modules/services/templates/action.tmpl.html',
Expand All @@ -52,28 +62,32 @@ function ServicesController(Services, ModalService, Notify, uiGridConstants, $st
vm.loading = true;

Services.read(null, { full : 1 })
.then(function (data) {
vm.gridOptions.data = data;
})
.catch(Notify.handleError)
.finally(function () {
vm.loading = false;
});
.then((data) => {
vm.gridOptions.data = data;

$timeout(() => {
countServiceByProject();
}, 0);
})
.catch(Notify.handleError)
.finally(() => {
vm.loading = false;
});
}

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

Services.delete(service.id)
.then(function () {
Notify.success('SERVICE.DELETED');
loadServices();
})
.catch(Notify.handleError);
});
Services.delete(service.id)
.then(() => {
Notify.success('SERVICE.DELETED');
loadServices();
})
.catch(Notify.handleError);
});
}

// update an existing service
Expand All @@ -86,5 +100,28 @@ function ServicesController(Services, ModalService, Notify, uiGridConstants, $st
$state.go('services.create');
}

// count services by project
function countServiceByProject() {
Services.count()
.then(data => {
let gridFooterTemplate = `<div class="ui-grid-footer-info ui-grid-grid-footer">`;
let total = 0;

data.forEach(row => {
total += row.total;
gridFooterTemplate += `<span><b>${row.project_abbr}</b>: ${row.total}</span> / `;
});

gridFooterTemplate += `
<span><b>Total</b>: ${total}</span>
</div>
`;

vm.gridOptions.showGridFooter = true;
vm.gridOptions.gridFooterTemplate = gridFooterTemplate;
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.OPTIONS);
})
.catch(Notify.handleError);
}
loadServices();
}
51 changes: 29 additions & 22 deletions client/src/modules/services/services.service.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
angular.module('bhima.services')
.service('ServiceService', ServiceService);
.service('ServiceService', ServiceService);

ServiceService.$inject = [ '$http', 'util' ];
ServiceService.$inject = ['$http', 'util'];

function ServiceService ($http, util) {
var service = this;
var baseUrl = '/services/';
function ServiceService($http, util) {
const service = this;
const baseUrl = '/services/';

service.create = create;
service.read = read;
service.update = update;
service.delete = del;
service.count = count;

function create(service) {
return $http.post(baseUrl, service)
.then(util.unwrapHttpResponse);
function create(_service_) {
return $http.post(baseUrl, _service_)
.then(util.unwrapHttpResponse);
}

function read(id, params) {
var url = baseUrl.concat(id || '');
return $http.get(url, { params : params })
.then(util.unwrapHttpResponse);
const url = baseUrl.concat(id || '');
return $http.get(url, { params })
.then(util.unwrapHttpResponse);
}

function update(id, service) {
delete service.abbr;
delete service.enterprise_name;
delete service.cc_id;
delete service.pc_id;
delete service.cost_center_name;
delete service.profit_center_name;
function count() {
const url = baseUrl.concat('count');
return $http.get(url)
.then(util.unwrapHttpResponse);
}

function update(id, _service_) {
delete _service_.abbr;
delete _service_.enterprise_name;
delete _service_.cc_id;
delete _service_.pc_id;
delete _service_.cost_center_name;
delete _service_.profit_center_name;

return $http.put(baseUrl + id, service)
.then(util.unwrapHttpResponse);
return $http.put(baseUrl + id, _service_)
.then(util.unwrapHttpResponse);
}

function del(id) {
return $http.delete(baseUrl + id)
.then(util.unwrapHttpResponse);
.then(util.unwrapHttpResponse);
}

return service;
}
}
9 changes: 5 additions & 4 deletions client/src/modules/templates/bhProjectSelect.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<div bh-project-select ng-model-options="{ updateOn: 'default' }">
<div ng-form="ProjectForm" bh-project-select ng-model-options="{ updateOn: 'default' }">
<div
class="form-group"
ng-class="{ 'has-error' : ProjectForm.$$parent.$submitted && ProjectForm.project_id.$invalid }">
ng-class="{ 'has-error' : ProjectForm.$submitted && ProjectForm.project_id.$invalid }">

<label class="control-label" translate>
FORM.LABELS.PROJECT
</label>
<ng-transclude></ng-transclude>
<ui-select name="project_id"
ng-model="$ctrl.projectId"
on-select="$ctrl.onSelect($item, $model)">
on-select="$ctrl.onSelect($item, $model)"
ng-required="$ctrl.required">
<ui-select-match placeholder="{{ 'FORM.SELECT.PROJECT' | translate }}"><span>{{$select.selected.name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="project.id as project in $ctrl.projects | filter: { 'name': $select.search }">
<span ng-bind-html="project.name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

<div class="help-block" ng-messages="ProjectForm.project_id.$error" ng-show="ProjectForm.$$parent.$submitted">
<div class="help-block" ng-messages="ProjectForm.project_id.$error" ng-show="ProjectForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ exports.configure = function configure(app) {
// API for service routes
app.post('/services', services.create);
app.get('/services', services.list);
app.get('/services/count', services.countServiceByProject);
app.get('/services/:id', services.detail);
app.put('/services/:id', services.update);
app.delete('/services/:id', services.remove);
Expand Down
Loading

0 comments on commit fc69b92

Please sign in to comment.