Skip to content

Commit

Permalink
Feat(Setting) donor management module
Browse files Browse the repository at this point in the history
closes #4826
  • Loading branch information
jeremielodi committed Aug 24, 2020
1 parent 6015853 commit f396289
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"WARNING": "Warning",
"CONFIRM_MODAL": "Confirmation Needed",
"DELETE_ROLE": "Do you really want to delete this role?",
"DELETE_DONOR": "Do you really want to delete this donor?",
"DELETE_SUPPLIER" : "Do you really want to delete this supplier?"
},
"ERRORS": {
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"DISPLAY_METADATA": "Display Metadata",
"DISTRIBUTION_KEYS": "Distribution Keys Management",
"DITRIBUTION_AUX_FEES_CENTERS" : "Distribution of Auxiliary Fee Centers",
"DONOR":"Donor",
"EMPLOYEE" : "Employee",
"EMPLOYEE_REGISTRY" : "Employee Registry",
"EMPLOYEE_STANDING_REPORT" : "Employee Standing Report",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"WARNING": "Attention",
"CONFIRM_MODAL": "La confirmation est nécessaire",
"DELETE_ROLE": "Voulez-vous vraiment supprimer ce rôle?",
"DELETE_DONOR": "Voulez-vous vraiment supprimer ce donateur?",
"DELETE_SUPPLIER" : "Voulez-vous supprimer ce fournisseur?"
},
"ERRORS": {
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"DITRIBUTION_AUX_FEES_CENTERS" : "Répartitions des centres de frais auxiliaires",
"DISPLAY_METADATA": "Afficher les métadonnées",
"DISTRIBUTION_KEYS": "Gestion des clés de répartitions",
"DONOR":"Donateur",
"EMPLOYEE":"Gestion des Employés",
"EMPLOYEE_REGISTRY" : "Registre des employés",
"EMPLOYEE_STANDING_REPORT" : "Rapport des employés",
Expand Down
87 changes: 87 additions & 0 deletions client/src/modules/donor/donor.ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
angular.module('bhima.controllers')
.controller('DonorController', DonorController);

DonorController.$inject = [
'$uibModal', 'DonorService', 'ModalService',
'NotifyService', 'uiGridConstants',
];

function DonorController($uibModal, Donor, Modal, Notify, uiGridConstants) {
const vm = this;

vm.createUpdateDonorModal = (selectedRole = {}) => {
$uibModal.open({
templateUrl : 'modules/donor/modal/createUpdate.html',
controller : 'DonorAddController as DonorAddCtrl',
resolve : { data : () => selectedRole },
});
};

vm.remove = function remove(id) {
const message = 'FORM.DIALOGS.DELETE_DONOR';
Modal.confirm(message)
.then(confirmResponse => {
if (!confirmResponse) {
return;
}
Donor.delete(id)
.then(() => {
Notify.success('FORM.INFO.DELETE_SUCCESS');
load();
})
.catch(Notify.handleError);
});
};

function load() {
vm.loading = true;

Donor.read()
.then(roles => {
vm.gridOptions.data = roles;
})
.catch(Notify.handleError)
.finally(() => {
vm.loading = false;
});
}

const columns = [{
field : 'display_name',
displayName : 'FORM.LABELS.NAME',
headerCellFilter : 'translate',
}, {
field : 'actions',
enableFiltering : false,
width : 100,
displayName : '',
headerCellFilter : 'translate',
cellTemplate : 'modules/donor/templates/action.cell.html',
}];

// ng-click="
vm.gridOptions = {
appScopeProvider : vm,
enableColumnMenus : false,
columnDefs : columns,
enableSorting : true,
data : [],
fastWatch : true,
flatEntityAccess : true,
onRegisterApi : (gridApi) => {
vm.gridApi = gridApi;
},
};

load();
/**
* @function toggleInlineFilter
*
* @description
* Switches the inline filter on and off.
*/
vm.toggleInlineFilter = function toggleInlineFilter() {
vm.gridOptions.enableFiltering = !vm.gridOptions.enableFiltering;
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
};
}
38 changes: 38 additions & 0 deletions client/src/modules/donor/donor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="flex-header">
<div class="bhima-title">
<ol class="headercrumb">
<li class="static" translate>TREE.ADMIN</li>
<li class="title" translate>TREE.DONOR</li>
</ol>

<div class="toolbar">
<div class="toolbar-item">
<button class="btn btn-default" ng-click="DonorCtrl.createUpdateDonorModal()" data-method="create">
<span class="fa fa-plus"></span>
<span translate class="text-capitalize">FORM.LABELS.ADD</span>
</button>
</div>
<bh-filter-toggle on-toggle="DonorCtrl.toggleInlineFilter()">
</bh-filter-toggle>
</div>
</div>
</div>

<!-- main content -->
<div class="flex-content">
<div class="container-fluid">
<div
id="roles-grid"
class="grid-full-height"
ui-grid="DonorCtrl.gridOptions"
ui-grid-auto-resize
ui-grid-resize-columns
ui-grid-move-columns>

<bh-grid-loading-indicator
loading-state="DonorCtrl.loading"
empty-state="DonorCtrl.gridOptions.data.length === 0">
</bh-grid-loading-indicator>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions client/src/modules/donor/donor.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('bhima.routes')
.config(['$stateProvider', function Provider($stateProvider) {

$stateProvider.state('donors', {
url : '/donors',
templateUrl : 'modules/donor/donor.html',
controller : 'DonorController as DonorCtrl',
});
}]);
15 changes: 15 additions & 0 deletions client/src/modules/donor/donor.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
angular.module('bhima.services')
.service('DonorService', DonorService);

DonorService.$inject = ['PrototypeApiService'];

/**
* Role Service
*
* A service wrapper for the /donors HTTP endpoint.
*
*/
function DonorService(Api) {
const service = new Api('/donors/');
return service;
}
39 changes: 39 additions & 0 deletions client/src/modules/donor/modal/createUpdate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<form name="donorForm" bh-submit="DonorAddCtrl.submit(donorForm)" novalidate>
<div class="modal-header">
<ol class="headercrumb">
<li>
<span translate>TREE.DONOR</span>

<label class="label label-warning text-uppercase" translate>
{{DonorAddCtrl.action}}
</label>
</li>
</ol>
</div>

<div class="modal-body">
<div class="row">
<div class="form-group" ng-class="{ 'has-error' : donorForm.display_name.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.NAME</label>
<input type="text" class="form-control col-md-9" name="label" ng-model="DonorAddCtrl.donor.display_name" required>
<div class="help-block" ng-messages="donorForm.label.$error" ng-show="donorForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
</div>

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

<bh-loading-button loading-state="donorForm.$loading">
</bh-loading-button>
</div>
</form>
36 changes: 36 additions & 0 deletions client/src/modules/donor/modal/createUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
angular.module('bhima.controllers')
.controller('DonorAddController', DonorAddController);

DonorAddController.$inject = [
'data', '$state', 'DonorService', 'NotifyService', '$uibModalInstance',
];

function DonorAddController(data, $state, DonorService, Notify, $uibModalInstance) {
const vm = this;
vm.close = $uibModalInstance.close;
vm.submit = submit;

vm.donor = angular.copy(data);
vm.isCreate = !vm.donor.uid;
vm.action = vm.isCreate ? 'FORM.LABELS.CREATE' : 'FORM.LABELS.UPDATE';

function submit(form) {
if (form.$invalid) {
Notify.danger('FORM.ERRORS.HAS_ERRORS');
return false;
}

const operation = (!data.id)
? DonorService.create(vm.donor)
: DonorService.update(data.id, vm.donor);

return operation
.then(() => {
Notify.success('FORM.INFO.OPERATION_SUCCESS');
$state.reload();
vm.close();
})
.catch(Notify.handleError);

}
}
28 changes: 28 additions & 0 deletions client/src/modules/donor/templates/action.cell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div
class="ui-grid-cell-contents text-right"
data-row="{{row.entity.display_name}}"
uib-dropdown dropdown-append-to-body>

<a uib-dropdown-toggle href data-action="open-dropdown-menu">
<span data-method="action" translate>FORM.BUTTONS.ACTIONS</span>
<span class="caret"></span>
</a>

<ul data-row-menu="{{ row.entity.display_name }}" class="dropdown-menu-right" bh-dropdown-menu-auto-dropup uib-dropdown-menu>
<li class="bh-dropdown-header">{{row.entity.display_name}}</li>
<li>
<a data-method="edit-record" ng-click="grid.appScope.createUpdateDonorModal(row.entity)" href>
<i class="fa fa-edit"></i> <span translate>FORM.BUTTONS.EDIT</span>
</a>
</li>

<li class="divider"></li>
<li>
<a data-method="delete-record" ng-click="grid.appScope.remove(row.entity.id)" href>
<span class="text-danger">
<i class="fa fa-trash"></i> <span translate>FORM.BUTTONS.DELETE</span>
</span>
</a>
</li>
</ul>
</div>
7 changes: 7 additions & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const install = require('../controllers/install');
// admin routes
const rolesCtrl = require('../controllers/admin/roles');
const users = require('../controllers/admin/users');
const donor = require('../controllers/admin/donor');
const projects = require('../controllers/admin/projects');
const enterprises = require('../controllers/admin/enterprises');
const services = require('../controllers/admin/services');
Expand Down Expand Up @@ -564,6 +565,12 @@ exports.configure = function configure(app) {
app.get('/users/:id/cashboxes', users.cashboxes.list);
app.post('/users/:id/cashboxes', users.cashboxes.create);

// donor controller
app.get('/donors', donor.read);
app.post('/donors', donor.create);
app.get('/donors/:id', donor.detail);
app.put('/donors/:id', donor.update);
app.delete('/donors/:id', donor.remove);
// projects controller
app.get('/projects/:id', projects.detail);
app.put('/projects/:id', projects.update);
Expand Down
44 changes: 44 additions & 0 deletions server/controllers/admin/donor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const db = require('../../lib/db');

module.exports = {
create,
update,
read,
remove,
detail,
};

function create(req, res, next) {
const data = req.body;
db.exec(`INSERT INTO donor SET ?`, data).then(() => {
res.sendStatus(201);
}).catch(next);
}

function update(req, res, next) {
const data = req.body;
const { id } = req.params;
db.exec(`UPDATE donor SET ? WHERE id=?`, [data, id]).then(() => {
res.sendStatus(200);
}).catch(next);
}

function read(req, res, next) {
db.exec(`SELECT id, display_name FROM donor`).then(donors => {
res.status(200).json(donors);
}).catch(next);
}

function detail(req, res, next) {
const { id } = req.params;
db.one(`SELECT id, display_name FROM donor WHERE id=?`, id).then(donor => {
res.status(200).json(donor);
}).catch(next);
}

function remove(req, res, next) {
const { id } = req.params;
db.exec(`DELETE FROM donor WHERE id=?`, id).then(() => {
res.sendStatus(200);
}).catch(next);
}
4 changes: 2 additions & 2 deletions server/models/bhima.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ INSERT INTO unit VALUES
(286,'Fee Center Reports','TREE.REPORTS','reports for the fee center modules',218,'/fee_center/reports'),
(287,'Inventory Reports','TREE.REPORTS','reports for the inventory modules', 138,'/inventory/reports'),
(288, '[Stock] Movement Report','TREE.STOCK_MOVEMENT_REPORT','Stock Movement Report', 282,'/reports/stock_movement_report'),
(289, '[Stock] Expiration report','TREE.STOCK_EXPIRATION_REPORT','Stock expiration report', 282,'/reports/stock_expiration_report');

(289, '[Stock] Expiration report','TREE.STOCK_EXPIRATION_REPORT','Stock expiration report', 282,'/reports/stock_expiration_report'),
(290,'Donors','TREE.DONOR','Donors management',1,'/donors');
-- Reserved system account type
INSERT INTO `account_category` VALUES
(1, 'income', 'ACCOUNT.TYPES.INCOME'),
Expand Down
8 changes: 8 additions & 0 deletions server/models/migrations/next/migrate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,11 @@ CREATE TABLE `lot_tag` (
FOREIGN KEY (`lot_uuid`) REFERENCES `lot` (`uuid`),
FOREIGN KEY (`tag_uuid`) REFERENCES `tags` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;

/*
@author : jeremielodi
@date : 2020-08-19
@subject : Donor management
*/
INSERT INTO unit VALUES
(290,'Donors','TREE.DONOR','Donors management',1,'/donors');
Loading

0 comments on commit f396289

Please sign in to comment.