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

Feat(Setting) donor management module #4837

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@
"WARNING": "Warning",
"CONFIRM_MODAL": "Confirmation Needed",
"DELETE_ROLE": "Do you really want to delete this role?",
"DELETE_SUPPLIER" : "Do you really want to delete this supplier?",
"UNPOST_TRANSACTIONS" : "Do you realy want to unpost transactions?"
"UNPOST_TRANSACTIONS" : "Do you realy want to unpost transactions?",
"DELETE_DONOR": "Do you really want to delete this donor?",
"DELETE_SUPPLIER" : "Do you really want to delete this supplier?"
},
"ERRORS": {
"AT_LEAST_1_COL": "At least one column must be selected",
Expand Down Expand Up @@ -911,6 +912,7 @@
"DATE_INTERVAL": "Select a date interval",
"DEBTOR_GROUP": "Select a Debtor Group",
"DEPOT": "Select a Depot",
"DONOR": "Select a donor",
"ENTERPRISE": "Select an Enterprise",
"FEE_CENTER": "Select a Fee Center",
"FISCAL_YEAR": "Select a Fiscal Year",
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
6 changes: 4 additions & 2 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@
"WARNING": "Attention",
"CONFIRM_MODAL": "La confirmation est nécessaire",
"DELETE_ROLE": "Voulez-vous vraiment supprimer ce rôle?",
"DELETE_SUPPLIER" : "Voulez-vous supprimer ce fournisseur?",
"UNPOST_TRANSACTIONS" : "Voulez-vous vraiment déposter les transactions?"
"UNPOST_TRANSACTIONS" : "Voulez-vous vraiment déposter les transactions?",
"DELETE_DONOR": "Voulez-vous vraiment supprimer ce donateur?",
"DELETE_SUPPLIER" : "Voulez-vous supprimer ce fournisseur?"
},
"ERRORS": {
"AT_LEAST_1_COL": "Au moins une colonne doit être sélectionnée",
Expand Down Expand Up @@ -912,6 +913,7 @@
"DATE_INTERVAL": "Sélectionner un intervalle de date",
"DEBTOR_GROUP": "Sélectionner un Groupe Débiteur",
"DEPOT": "Sélectionner un dépôt",
"DONOR": "Sélectionner un donateur",
"ENTERPRISE": "Sélectionner une entreprise",
"FEE_CENTER": "Sélectionner un centre de frais",
"FISCAL_YEAR": "Sélectionner une année fiscale",
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
1 change: 1 addition & 0 deletions client/src/js/components/bhDateEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ angular.module('bhima.components')
maxDate : '<?',
allowFutureDate : '<?',
disabled : '<?',
required : '<',
dateFormat : '@?',
label : '@?',
limitMinFiscal : '@?',
Expand Down
22 changes: 22 additions & 0 deletions client/src/modules/donor/donation.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
angular.module('bhima.services')
.service('DonationService', DonationService);

DonationService.$inject = ['PrototypeApiService'];

/**
* Role Service
*
* A service wrapper for the /donors HTTP endpoint.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This service is for /donors or /donations ? If it is for /donations you could update this line

*
*/
function DonationService(Api) {
const service = new Api('/donations/');
service.stockBalance = stockBalance;

function stockBalance(id) {
const url = ''.concat(id, '/stock_balance');
return Api.read.call(service, url);
}

return service;
}
103 changes: 103 additions & 0 deletions client/src/modules/donor/donor.ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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 = {}) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this parameter is not related to role may be selectedDonor is a better name

$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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

donors in place of roles will be better

})
.catch(Notify.handleError)
.finally(() => {
vm.loading = false;
});
}

const columns = [{
field : 'display_name',
displayName : 'FORM.LABELS.NAME',
headerCellFilter : 'translate',
},
{
field : 'phone',
displayName : 'FORM.LABELS.PHONE',
headerCellFilter : 'translate',
},
{
field : 'email',
displayName : 'FORM.LABELS.EMAIL',
headerCellFilter : 'translate',
},
{
field : 'address',
displayName : 'FORM.LABELS.ADDRESS',
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="donor-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;
}
65 changes: 65 additions & 0 deletions client/src/modules/donor/modal/createUpdate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<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">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you remove this <div class="row"> it is not necessary

<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 class="form-group" ng-class="{ 'has-error' : donorForm.phone.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.PHONE</label>
<input type="tel" class="form-control col-md-9" name="phone" ng-model="DonorAddCtrl.donor.phone">
<div class="help-block" ng-messages="donorForm.phone.$error" ng-show="donorForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>


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


<div class="form-group" ng-class="{ 'has-error' : donorForm.address.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.ADDRESS</label>
<input type="text" class="form-control col-md-9" name="address" ng-model="DonorAddCtrl.donor.address">
<div class="help-block" ng-messages="donorForm.address.$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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the controller is not only for creation of donors, so you could rename this controller to something like : DonorCreateAndUpdateController, DonorManagementController, etc.


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>
Loading