-
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.
3724: (Report) Stock entry report r=jniles a=mbayopanda This PR adds the stock entry report. ![image](https://user-images.githubusercontent.com/5445251/57624961-dc17e180-758a-11e9-87a8-d751ef0d866a.png) Co-authored-by: mbayopanda <mbayopanda@gmail.com>
- Loading branch information
Showing
20 changed files
with
742 additions
and
13 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
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
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
87 changes: 87 additions & 0 deletions
87
client/src/modules/reports/generate/stock_entry/stock_entry.config.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,87 @@ | ||
angular.module('bhima.controllers') | ||
.controller('stock_entryController', StockEntryConfigController); | ||
|
||
StockEntryConfigController.$inject = [ | ||
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state', | ||
'LanguageService', | ||
]; | ||
|
||
function StockEntryConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, Languages) { | ||
const vm = this; | ||
const cache = new AppCache('configure_stock_entry_report'); | ||
const reportUrl = 'reports/stock/entry'; | ||
|
||
// default values | ||
vm.reportDetails = { | ||
includePurchaseEntry : 1, | ||
}; | ||
vm.previewGenerated = false; | ||
vm.onEntryTypeChange = onEntryTypeChange; | ||
|
||
// check cached configuration | ||
checkCachedConfiguration(); | ||
|
||
// check checked entry type | ||
onEntryTypeChange(); | ||
|
||
vm.onSelectDepot = depot => { | ||
vm.reportDetails.depotUuid = depot.uuid; | ||
}; | ||
|
||
vm.clear = key => { | ||
delete vm[key]; | ||
}; | ||
|
||
vm.clearPreview = () => { | ||
vm.previewGenerated = false; | ||
vm.previewResult = null; | ||
}; | ||
|
||
vm.preview = form => { | ||
if (form.$invalid) { | ||
return 0; | ||
} | ||
|
||
if (!vm.hasOneChecked) { | ||
return 0; | ||
} | ||
|
||
// update cached configuration | ||
cache.reportDetails = angular.copy(vm.reportDetails); | ||
angular.extend(vm.reportDetails, { lang : Languages.key }); | ||
|
||
return SavedReports.requestPreview(reportUrl, reportData.id, angular.copy(vm.reportDetails)) | ||
.then((result) => { | ||
vm.previewGenerated = true; | ||
vm.previewResult = $sce.trustAsHtml(result); | ||
}) | ||
.catch(Notify.handleError); | ||
}; | ||
|
||
vm.requestSaveAs = function requestSaveAs() { | ||
const options = { | ||
url : reportUrl, | ||
report : reportData, | ||
reportOptions : angular.copy(vm.reportDetails), | ||
}; | ||
|
||
return SavedReports.saveAsModal(options) | ||
.then(() => { | ||
$state.go('reportsBase.reportsArchive', { key : options.report.report_key }); | ||
}) | ||
.catch(Notify.handleError); | ||
}; | ||
|
||
function checkCachedConfiguration() { | ||
vm.reportDetails = angular.copy(cache.reportDetails || {}); | ||
} | ||
|
||
function onEntryTypeChange() { | ||
// be sure at least one checkbox is checked | ||
const sum = vm.reportDetails.includePurchaseEntry | ||
+ vm.reportDetails.includeIntegrationEntry | ||
+ vm.reportDetails.includeDonationEntry | ||
+ vm.reportDetails.includeTransferEntry; | ||
vm.hasOneChecked = sum > 0; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
client/src/modules/reports/generate/stock_entry/stock_entry.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,92 @@ | ||
<bh-report-preview | ||
ng-if="ReportConfigCtrl.previewGenerated" | ||
source-document="ReportConfigCtrl.previewResult" | ||
on-clear-callback="ReportConfigCtrl.clearPreview()" | ||
on-save-callback="ReportConfigCtrl.requestSaveAs()"> | ||
</bh-report-preview> | ||
|
||
<div ng-show="!ReportConfigCtrl.previewGenerated"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<h3 translate>REPORT.STOCK.ENTRY_REPORT</h3> | ||
<p class="text-info" translate>REPORT.STOCK.ENTRY_REPORT_DESCRIPTION</p> | ||
</div> | ||
</div> | ||
|
||
<div class="row" style="margin-top : 10px"> | ||
<div class="col-md-6"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<span translate>REPORT.UTIL.OPTIONS</span> | ||
</div> | ||
|
||
<div class="panel-body"> | ||
|
||
<form name="ConfigForm" bh-submit="ReportConfigCtrl.preview(ConfigForm)" novalidate autocomplete="off"> | ||
|
||
<!-- select depot --> | ||
<bh-depot-select | ||
depot-uuid="ReportConfigCtrl.reportDetails.depotUuid" | ||
on-select-callback="ReportConfigCtrl.onSelectDepot(depot)" | ||
required="true"> | ||
</bh-depot-select> | ||
|
||
<!-- date interval --> | ||
<bh-date-interval | ||
date-from="ReportConfigCtrl.reportDetails.dateFrom" | ||
date-to="ReportConfigCtrl.reportDetails.dateTo" | ||
limit-min-fiscal | ||
required="true"> | ||
</bh-date-interval> | ||
|
||
<!-- stock entry type --> | ||
<div ng-class="{'has-error': ConfigForm.$submitted && !ReportConfigCtrl.hasOneChecked}"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includePurchaseEntry"> | ||
<span translate>REPORT.STOCK.INCLUDE_PURCHASE_ENTRY</span> | ||
</label> | ||
</div> | ||
|
||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeIntegrationEntry"> | ||
<span translate>REPORT.STOCK.INCLUDE_INTEGRATION_ENTRY</span> | ||
</label> | ||
</div> | ||
|
||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeDonationEntry"> | ||
<span translate>REPORT.STOCK.INCLUDE_DONATION_ENTRY</span> | ||
</label> | ||
</div> | ||
|
||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeTransferEntry"> | ||
<span translate>REPORT.STOCK.INCLUDE_TRANSFER_ENTRY</span> | ||
</label> | ||
</div> | ||
<em ng-if="ConfigForm.$submitted && !ReportConfigCtrl.hasOneChecked" class="help-block" translate>STOCK.AT_LEAST_ONE_CHECKED</em> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-model="ReportConfigCtrl.reportDetails.showDetails"> | ||
<span translate>REPORT.STOCK.SHOW_DETAILS</span> | ||
</label> | ||
</div> | ||
|
||
<!-- preview --> | ||
<bh-loading-button loading-state="ConfigForm.$loading"> | ||
<span translate>REPORT.UTIL.PREVIEW</span> | ||
</bh-loading-button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
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
38 changes: 38 additions & 0 deletions
38
server/controllers/stock/reports/stock/entry/entryFromDonation.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,38 @@ | ||
const db = require('../../../../../lib/db'); | ||
|
||
const IS_EXIT = 0; | ||
const ENTRY_FROM_DONATION_ID = 6; | ||
|
||
/** | ||
* @function fetch | ||
* @description fetch stock entry from donation | ||
*/ | ||
function fetch(depotUuid, dateFrom, dateTo, showDetails) { | ||
const sql = ` | ||
SELECT | ||
i.code, i.text, iu.text AS unit_text, BUID(m.document_uuid) AS document_uuid, | ||
SUM(m.quantity) as quantity, m.date, m.description, | ||
u.display_name AS user_display_name, | ||
dm.text AS document_reference, d.text AS depot_name | ||
FROM stock_movement m | ||
JOIN lot l ON l.uuid = m.lot_uuid | ||
JOIN inventory i ON i.uuid = l.inventory_uuid | ||
JOIN inventory_unit iu ON iu.id = i.unit_id | ||
JOIN depot d ON d.uuid = m.depot_uuid | ||
JOIN user u ON u.id = m.user_id | ||
LEFT JOIN document_map dm ON dm.uuid = m.document_uuid | ||
WHERE m.is_exit = ${IS_EXIT} AND m.flux_id = ${ENTRY_FROM_DONATION_ID} AND d.uuid = ? | ||
AND (DATE(m.date) BETWEEN DATE(?) AND DATE(?)) | ||
GROUP BY i.uuid`; | ||
|
||
const groupBy = ', m.uuid'; | ||
const orderBy = ' ORDER BY i.text, m.date ASC'; | ||
const query = showDetails ? sql.concat(groupBy, orderBy) : sql.concat(orderBy); | ||
|
||
const _depotUuid = db.bid(depotUuid); | ||
const _dateFrom = new Date(dateFrom); | ||
const _dateTo = new Date(dateTo); | ||
return db.exec(query, [_depotUuid, _dateFrom, _dateTo]); | ||
} | ||
|
||
module.exports.fetch = fetch; |
38 changes: 38 additions & 0 deletions
38
server/controllers/stock/reports/stock/entry/entryFromIntegration.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,38 @@ | ||
const db = require('../../../../../lib/db'); | ||
|
||
const IS_EXIT = 0; | ||
const ENTRY_FROM_INTEGRATION_ID = 13; | ||
|
||
/** | ||
* @function fetch | ||
* @description fetch stock entry from integration | ||
*/ | ||
function fetch(depotUuid, dateFrom, dateTo, showDetails) { | ||
const sql = ` | ||
SELECT | ||
i.code, i.text, iu.text AS unit_text, BUID(m.document_uuid) AS document_uuid, | ||
SUM(m.quantity) as quantity, m.date, m.description, | ||
u.display_name AS user_display_name, | ||
dm.text AS document_reference, d.text AS depot_name | ||
FROM stock_movement m | ||
JOIN lot l ON l.uuid = m.lot_uuid | ||
JOIN inventory i ON i.uuid = l.inventory_uuid | ||
JOIN inventory_unit iu ON iu.id = i.unit_id | ||
JOIN depot d ON d.uuid = m.depot_uuid | ||
JOIN user u ON u.id = m.user_id | ||
LEFT JOIN document_map dm ON dm.uuid = m.document_uuid | ||
WHERE m.is_exit = ${IS_EXIT} AND m.flux_id = ${ENTRY_FROM_INTEGRATION_ID} AND d.uuid = ? | ||
AND (DATE(m.date) BETWEEN DATE(?) AND DATE(?)) | ||
GROUP BY i.uuid`; | ||
|
||
const groupBy = ', m.uuid'; | ||
const orderBy = ' ORDER BY i.text, m.date ASC'; | ||
const query = showDetails ? sql.concat(groupBy, orderBy) : sql.concat(orderBy); | ||
|
||
const _depotUuid = db.bid(depotUuid); | ||
const _dateFrom = new Date(dateFrom); | ||
const _dateTo = new Date(dateTo); | ||
return db.exec(query, [_depotUuid, _dateFrom, _dateTo]); | ||
} | ||
|
||
module.exports.fetch = fetch; |
Oops, something went wrong.