-
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
b7cc0d3
commit 9b7f65c
Showing
19 changed files
with
748 additions
and
9 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
97 changes: 97 additions & 0 deletions
97
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,97 @@ | ||
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.includePurchaseEntry = 1; | ||
vm.includeIntegrationEntry = 0; | ||
vm.includeDonationEntry = 0; | ||
vm.includeTransferEntry = 0; | ||
vm.previewGenerated = false; | ||
vm.onEntryTypeChange = onEntryTypeChange; | ||
|
||
// check cached configuration | ||
checkCachedConfiguration(); | ||
|
||
// check checked entry type | ||
onEntryTypeChange(); | ||
|
||
vm.onSelectDepot = depot => { | ||
vm.depot = depot; | ||
}; | ||
|
||
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; | ||
} | ||
|
||
const params = { | ||
depotUuid : vm.depot.uuid, | ||
dateFrom : vm.dateFrom, | ||
dateTo : vm.dateTo, | ||
includePurchaseEntry : vm.includePurchaseEntry, | ||
includeIntegrationEntry : vm.includeIntegrationEntry, | ||
includeDonationEntry : vm.includeDonationEntry, | ||
includeTransferEntry : vm.includeTransferEntry, | ||
showDetails : vm.showDetails, | ||
}; | ||
|
||
// update cached configuration | ||
cache.reportDetails = angular.copy(params); | ||
angular.extend(vm.reportDetails, params, { 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.includePurchaseEntry | ||
+ vm.includeIntegrationEntry + vm.includeDonationEntry + vm.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.depot.uuid" | ||
on-select-callback="ReportConfigCtrl.onSelectDepot(depot)" | ||
required="true"> | ||
</bh-depot-select> | ||
|
||
<!-- date interval --> | ||
<bh-date-interval | ||
date-from="ReportConfigCtrl.dateFrom" | ||
date-to="ReportConfigCtrl.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.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.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.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.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.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.