Skip to content

Commit

Permalink
feat(stock): add search by voucher reference
Browse files Browse the repository at this point in the history
Adds the ability to search for a particular stock movement by its
voucher reference if auto_stock_accounting is enabled.

Closes #5508.
  • Loading branch information
jniles committed Mar 14, 2021
1 parent efbb3d6 commit d7c7bb8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 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 @@ -664,6 +664,7 @@
"RECORDS": "Records (Rows)",
"REFERENCE_GROUP": "Reference Group",
"REFERENCE_PATIENT": "Patient Reference",
"REFERENCE_VOUCHER" : "Voucher Reference",
"REFERENCE": "Reference",
"REFERENCES": "References",
"REGISTER_EMPLOYEE_PATIENT": "Save as an employee",
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 @@ -665,6 +665,7 @@
"RECORDS": "Enregistrements (Lignes)",
"REFERENCE_GROUP": "Groupe de référence",
"REFERENCE_PATIENT": "Référence Patient",
"REFERENCE_VOUCHER": "Référence Bordereau",
"REFERENCE": "Référence",
"REFERENCES": "Références",
"REGISTER_EMPLOYEE_PATIENT": "Enregistrer comme un employé",
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/StockFilterer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function StockFiltererService(Filters, AppCache, $httpParamSerializer, Languages
{ key : 'is_expired', label : 'STOCK.EXPIRED' },
{ key : 'is_expiry_risk', label : 'STOCK.STATUS.IS_IN_RISK_OF_EXPIRATION' },
{ key : 'tag_uuid', label : 'TAG.LABEL' },
{ key : 'voucherReference', label : 'FORM.LABELS.REFERENCE_VOUCHER' },
{ key : 'tags', label : 'TAG.LABEL' },
{ key : 'show_only_risky', label : 'LOTS.SHOW_ONLY_RISKY_LOTS' },
{ key : 'stock_requisition_uuid', label : 'FORM.LABELS.REQUISITION_REFERENCE' },
Expand Down
20 changes: 12 additions & 8 deletions client/src/modules/stock/movements/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
</div>
</div>

<!-- reference -->
<div class="form-group" ng-class="{ 'has-error' : ModalForm.reference.$invalid }">
<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.reference.$invalid }">
<label class="control-label" translate>FORM.LABELS.REFERENCE</label>
<bh-clear on-clear="$ctrl.clear('reference')"></bh-clear>
<input
name="reference"
class="form-control"
ng-model="$ctrl.searchQueries.reference"
ng-change="$ctrl.onSelectReference($ctrl.searchQueries.reference)">
<input type="text" class="form-control" name="reference" ng-model="$ctrl.searchQueries.reference">
<div class="help-block" ng-messages="ModalForm.reference.$error" ng-show="ModalForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="help-block" ng-messages="ModalForm.reference.$error">
<!-- voucher reference -->
<div class="form-group" ng-class="{ 'has-error' : ModalForm.voucherReference.$invalid }" ng-if="$ctrl.hasAutoStockAccounting">
<label class="control-label" translate>FORM.LABELS.REFERENCE_VOUCHER</label>
<bh-clear on-clear="$ctrl.clear('voucherReference')"></bh-clear>
<input name="voucherReference" class="form-control" ng-model="$ctrl.searchQueries.voucherReference">
<div class="help-block" ng-messages="ModalForm.voucherReference.$error">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions client/src/modules/stock/movements/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ angular.module('bhima.controllers')
SearchMovementsModalController.$inject = [
'data', '$uibModalInstance',
'PeriodService', 'Store', 'util', 'StockService',
'SearchModalUtilService',
'SearchModalUtilService', 'SessionService',
];

function SearchMovementsModalController(data, Instance, Periods, Store, util, Stock, SearchModal) {
function SearchMovementsModalController(data, Instance, Periods, Store, util, Stock, SearchModal, Session) {
const vm = this;
const displayValues = {};
const changes = new Store({ identifier : 'key' });

const searchQueryOptions = [
'is_exit', 'depot_uuid', 'inventory_uuid', 'label', 'flux_id',
'dateFrom', 'dateTo', 'user_id', 'patientReference', 'service_uuid', 'invoice_uuid',
'stock_requisition_uuid',
'stock_requisition_uuid', 'voucherReference',
];

vm.hasAutoStockAccounting = Session.stock_settings.enable_auto_stock_accounting;

vm.filters = data;
vm.searchQueries = {};
vm.defaultQueries = {};
Expand Down
7 changes: 7 additions & 0 deletions server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ function getLotFilters(parameters) {
filters.equals('tag_uuid', 'tags', 't');
filters.equals('stock_requisition_uuid', 'stock_requisition_uuid', 'm');

// filter on the underlying voucher t
filters.custom('voucherReference',
`document_uuid = (
SELECT DISTINCT vi.document_uuid FROM voucher_item AS vi
WHERE vi.voucher_uuid = (SELECT uuid FROM document_map WHERE document_map.text = ?)
)`);

// depot permission check
filters.custom(
'check_user_id',
Expand Down

0 comments on commit d7c7bb8

Please sign in to comment.