-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f220c39
commit 2f29aca
Showing
7 changed files
with
283 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
angular.module('bhima.services') | ||
.service('DonationService', DonationService); | ||
|
||
DonationService.$inject = ['PrototypeApiService']; | ||
|
||
/** | ||
* Role Service | ||
* | ||
* A service wrapper for the /donors HTTP endpoint. | ||
* | ||
*/ | ||
function DonationService(Api) { | ||
const service = new Api('/donations/'); | ||
return service; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
client/src/modules/stock/entry/modals/findDonation.modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<form | ||
name="FindForm" | ||
bh-submit="$ctrl.submit(FindForm)" | ||
novalidate> | ||
|
||
<div class="modal-header space-between"> | ||
<div class="headercrumb"> | ||
<i class="fa fa-search"></i> | ||
<span translate>FORM.LABELS.SEARCH</span> | ||
<span translate>STOCK.ENTRY_DONATION</span> | ||
</div> | ||
|
||
<div class="toolbar text-right"> | ||
<div class="toolbar-item"> | ||
<button type="button" | ||
ng-click="$ctrl.toggleFilter()" | ||
class="btn btn-sm btn-default" | ||
ng-class="{ 'btn-info' : $ctrl.filterEnabled }"> | ||
<span class="fa fa-filter"></span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<div | ||
id="PurchaseGrid" | ||
ui-grid="$ctrl.gridOptions" | ||
ui-grid-auto-resize | ||
ui-grid-resize-columns | ||
ui-grid-selection> | ||
<bh-grid-loading-indicator | ||
loading-state="$ctrl.loading" | ||
empty-state="$ctrl.gridOptions.data.length === 0" | ||
error-state="$ctrl.hasError"> | ||
</bh-grid-loading-indicator> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" ng-click="$ctrl.cancel()" data-method="cancel" translate> | ||
FORM.BUTTONS.CLOSE | ||
</button> | ||
|
||
<bh-loading-button loading-state="FindForm.$loading"> | ||
<span translate>FORM.BUTTONS.SUBMIT</span> | ||
</bh-loading-button> | ||
</div> | ||
|
||
</form> |
117 changes: 117 additions & 0 deletions
117
client/src/modules/stock/entry/modals/findDonation.modal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
angular.module('bhima.controllers') | ||
.controller('StockFindDonationModalController', StockFindDonationModalController); | ||
|
||
StockFindDonationModalController.$inject = [ | ||
'$uibModalInstance', 'DonationService', 'NotifyService', | ||
'uiGridConstants', 'GridFilteringService', 'ReceiptModal', | ||
'bhConstants', | ||
]; | ||
|
||
function StockFindDonationModalController( | ||
Instance, Donation, Notify, | ||
uiGridConstants, Filtering, Receipts, bhConstants, | ||
) { | ||
const vm = this; | ||
|
||
// global | ||
vm.selectedRow = {}; | ||
|
||
/* ======================= Grid configurations ============================ */ | ||
vm.filterEnabled = false; | ||
vm.gridOptions = { appScopeProvider : vm }; | ||
|
||
const filtering = new Filtering(vm.gridOptions); | ||
|
||
const columns = [ | ||
{ | ||
field : 'reference', | ||
displayName : 'TABLE.COLUMNS.REFERENCE', | ||
headerCellFilter : 'translate', | ||
cellTemplate : 'modules/stock/entry/modals/templates/purchase_reference.tmpl.html', | ||
}, | ||
|
||
{ | ||
field : 'date', | ||
cellFilter : 'date:"'.concat(bhConstants.dates.format, '"'), | ||
filter : { condition : filtering.filterByDate }, | ||
displayName : 'TABLE.COLUMNS.DATE', | ||
headerCellFilter : 'translate', | ||
sort : { priority : 0, direction : 'desc' }, | ||
}, | ||
|
||
{ | ||
field : 'display_name', | ||
displayName : 'TREE.DONOR', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'project_name', | ||
displayName : 'FORM.LABELS.PROJECT', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'description', | ||
displayName : 'FORM.LABELS.DESCRIPTION', | ||
headerCellFilter : 'translate', | ||
}, | ||
]; | ||
|
||
vm.gridOptions.columnDefs = columns; | ||
vm.gridOptions.multiSelect = false; | ||
vm.gridOptions.enableFiltering = vm.filterEnabled; | ||
vm.gridOptions.onRegisterApi = onRegisterApi; | ||
vm.toggleFilter = toggleFilter; | ||
|
||
// bind methods | ||
vm.submit = submit; | ||
vm.cancel = cancel; | ||
vm.showReceipt = showReceipt; | ||
|
||
function onRegisterApi(gridApi) { | ||
vm.gridApi = gridApi; | ||
vm.gridApi.selection.on.rowSelectionChanged(null, rowSelectionCallback); | ||
} | ||
|
||
function rowSelectionCallback(row) { | ||
vm.selectedRow = row.entity; | ||
} | ||
|
||
/** toggle filter */ | ||
function toggleFilter() { | ||
vm.filterEnabled = !vm.filterEnabled; | ||
vm.gridOptions.enableFiltering = vm.filterEnabled; | ||
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN); | ||
} | ||
|
||
/** get purchase document */ | ||
function showReceipt(uuid) { | ||
Receipts.purchase(uuid); | ||
} | ||
|
||
/* ======================= End Grid ======================================== */ | ||
function load() { | ||
vm.loading = true; | ||
Donation.read() | ||
.then(donations => { | ||
vm.gridOptions.data = donations; | ||
}) | ||
.catch(() => { | ||
vm.hasError = true; | ||
}) | ||
.finally(() => { | ||
vm.loading = false; | ||
}); | ||
} | ||
|
||
// submit | ||
function submit() { | ||
if (!vm.selectedRow || (vm.selectedRow && !vm.selectedRow.uuid)) { return null; } | ||
return Instance.close([].concat(vm.selectedRow)); | ||
} | ||
// cancel | ||
function cancel() { | ||
Instance.close(); | ||
} | ||
|
||
load(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const db = require('../../lib/db'); | ||
|
||
module.exports = { | ||
create, | ||
update, | ||
read, | ||
remove, | ||
detail, | ||
}; | ||
|
||
function create(req, res, next) { | ||
const data = req.body; | ||
data.uuid = data.uuid ? db.bid(data.uuid) : db.uuid(); | ||
|
||
db.exec(`INSERT INTO donation SET ?`, data).then(() => { | ||
res.sendStatus(201); | ||
}).catch(next); | ||
} | ||
|
||
function update(req, res, next) { | ||
const data = req.body; | ||
const { uuid } = req.params; | ||
db.exec(`UPDATE donation SET ? WHERE uuid=?`, [data, db.bid(uuid)]).then(() => { | ||
res.sendStatus(200); | ||
}).catch(next); | ||
} | ||
|
||
function read(req, res, next) { | ||
const sql = ` | ||
SELECT BUID(dt.uuid) as uuid, dt.reference, dt.project_id, | ||
dt.description, | ||
dt.date, | ||
dt.donor_id, d.display_name, p.name as project_name | ||
FROM donation dt | ||
JOIN project p ON p.id= dt.project_id | ||
JOIN donor d ON d.id= dt.donor_id | ||
`; | ||
|
||
db.exec(sql).then(donations => { | ||
res.status(200).json(donations); | ||
}).catch(next); | ||
} | ||
|
||
function detail(req, res, next) { | ||
const sql = ` | ||
SELECT BUID(uuid) as uuid, reference, project_id, description, date, donor_id | ||
FROM donation | ||
WHERE uuid=?`; | ||
const { uuid } = req.params; | ||
db.one(sql, db.bid(uuid)).then(donation => { | ||
res.status(200).json(donation); | ||
}).catch(next); | ||
} | ||
|
||
function remove(req, res, next) { | ||
const { uuid } = req.params; | ||
db.exec(`DELETE FROM donation WHERE uuid=?`, db.bid(uuid)).then(() => { | ||
res.sendStatus(200); | ||
}).catch(next); | ||
} |