Skip to content

Commit

Permalink
wip(stock exit): clear grid on setExitType()
Browse files Browse the repository at this point in the history
This commit make the grid get reset when a new exit type is selected.
  • Loading branch information
jniles committed Mar 4, 2022
1 parent fc6b8a2 commit 4378f69
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
5 changes: 4 additions & 1 deletion client/src/js/components/bhStockOut/bhStockOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ function bhStockOutController(Depots, moment, Notify, $filter, $q) {
const dateTo = $ctrl.date || new Date();
$ctrl.loading = true;

// format date
const dateToFormatted = $date(dateTo, 'yyyy-MM-dd');

$q.all([
Depots.getStockOutsForDate($ctrl.depotUuid, dateTo),
Depots.getStockOutsForDate($ctrl.depotUuid, dateToFormatted),
Depots.read($ctrl.depotUuid),
])
.then(([inventories, depot]) => {
Expand Down
17 changes: 11 additions & 6 deletions client/src/modules/stock/LotItem.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
angular.module('bhima.services')
.service('LotItemService', LotItemService);
angular.module('bhima.services').service('LotItemService', LotItemService);

LotItemService.$inject = ['uuid', '$translate'];

Expand Down Expand Up @@ -146,7 +145,7 @@ function LotItemService(uuid, $translate) {
* @function hasLotInformation
*
* @description
* Checks if the lot information is availability.
* Checks if the lot information is available.
*/
Lot.prototype.hasLotInformation = function hasLotInformation() {
const hasInfo = isUuid(this.lot_uuid)
Expand Down Expand Up @@ -176,8 +175,8 @@ function LotItemService(uuid, $translate) {
* it is considered valid.
* 4) If no comparison date is provided, the same comparison is performed with today's
* date (the date of the client computer). Thus, if the expiration date is before
* the current date, the lot is considered expired. If the expiration date is after
* the current date, it is considered not expired.
* the current date, the lot is considered expired. If the expiration date is the
* same or after the current date, it is considered not expired.
*/
Lot.prototype.isExpired = function isExpired(comparisonDate = new Date()) {

Expand Down Expand Up @@ -348,7 +347,13 @@ function LotItemService(uuid, $translate) {
this.__tracking_consumption = bool;
};

//
/**
* @function formatForExport
*
* @description
* This function formats the lot for export to CSV using the ui-grid's
* internal CSV exporter.
*/
Lot.prototype.formatForExport = function formatForExport() {
return [
this.code,
Expand Down
21 changes: 14 additions & 7 deletions client/src/modules/stock/StockExitForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.services')
StockExitFormService.$inject = [
'Store', 'AppCache', 'SessionService', '$timeout', 'bhConstants', 'DepotService',
'Pool', 'LotItemService', 'StockExitFormHelperService', 'util', '$translate',
'StockService',
'StockService', '$filter',
];

/**
Expand All @@ -16,14 +16,15 @@ StockExitFormService.$inject = [
function StockExitFormService(
Store, AppCache, Session, $timeout, bhConstants,
Depots, Pool, Lot, Helpers, util, $translate,
Stock,
Stock, $filter,
) {

const {
TO_PATIENT, TO_LOSS, TO_SERVICE, TO_OTHER_DEPOT,
} = bhConstants.flux;

const today = new Date();
const $date = $filter('date');

const INFO_NO_EXIT_TYPE = 'STOCK.MESSAGES.INFO_NO_EXIT_TYPE';
const INFO_NEEDS_LOTS = 'STOCK.MESSAGES.INFO_NEEDS_LOTS';
Expand Down Expand Up @@ -122,14 +123,15 @@ function StockExitFormService(
* @function fetchQuantityInStock
*
* @description
* Loads the quantity in stock for the depot
*
* Loads the quantity in stock for the depot at a given date.
*
*/
StockExitForm.prototype.fetchQuantityInStock = function fetchQuantityInStock(depotUuid, date) {
if (!depotUuid || !date) { return {}; }

const parameters = { consumable : 1, inStock : true, date };
// format date into something that can be cached.
const dateFormatted = $date(date, 'yyyy-MM-dd');
const parameters = { consumable : 1, inStock : true, date : dateFormatted };

this._queriesInProgress++;

Expand Down Expand Up @@ -235,7 +237,7 @@ function StockExitFormService(

// reset store by releasing all locks on items
// and clearing the data
this.store.data.forEach(item => this.pool.release(item.lot_uuid));
this.store.data.forEach(item => this._pool.release(item.lot_uuid));
this.store.clear();
};

Expand Down Expand Up @@ -265,7 +267,12 @@ function StockExitFormService(
});

const hasNoConsumableItems = (available.length === 0 && unavailable.length === 0);
this._toggleInfoMessage(hasNoConsumableItems, 'warn', WARN_NOT_CONSUMABLE_INVOICE, { ...this.details, inventories });
this._toggleInfoMessage(
hasNoConsumableItems,
'warn',
WARN_NOT_CONSUMABLE_INVOICE,
{ ...this.details, inventories },
);

// if there are no consumable items in the invoice, this will exit early
if (hasNoConsumableItems) {
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function StockExitController(
}

vm.validate();
// vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
}

vm.setDate = function setDate(date) {
Expand Down

0 comments on commit 4378f69

Please sign in to comment.