Skip to content

Commit

Permalink
wip(stock): grid export works again
Browse files Browse the repository at this point in the history
  • Loading branch information
jniles committed Mar 4, 2022
1 parent a44b874 commit fc6b8a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
16 changes: 14 additions & 2 deletions client/src/modules/stock/LotItem.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ function LotItemService(uuid, $translate) {
this.text = null;
this.group_uuid = null;
this.unit = null;
this.unit_cost = null;

// lot properties
this.lot_uuid = null;
this.label = null;
this.quantity = 0;
this.unit_cost = 0;
this.expiration_date = null;

// validation properities
Expand Down Expand Up @@ -350,5 +348,19 @@ function LotItemService(uuid, $translate) {
this.__tracking_consumption = bool;
};

//
Lot.prototype.formatForExport = function formatForExport() {
return [
this.code,
this.text,
this.label,
this.quantity,
this.unit,
this._quantity_available,
this.expiration_date.toLocaleString(),
]
.map(value => ({ value }));
};

return Lot;
}
17 changes: 10 additions & 7 deletions client/src/modules/stock/StockExitForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ function StockExitFormService(
*
* @description
* This sets the exit type.
*
* TODO(@jniles) - is there more logic for this?
*/
StockExitForm.prototype.setExitType = function setExitType(type) {
this.details.exit_type = type;
Expand Down Expand Up @@ -259,8 +257,6 @@ function StockExitFormService(
.forEach(inventory => {
const matches = this.listLotsForInventory(inventory[uuidKey]);

console.log('matches:', matches);

if (matches.length > 0) {
available.push(inventory);
} else {
Expand All @@ -279,7 +275,6 @@ function StockExitFormService(
// adds a lot to the grid.
const addLotWithQuantity = (item, quantity) => {
const lot = new Lot(item);
console.log('item:', item);
lot._quantity_available = item._quantity_available;
lot.quantity = quantity;
lot.validate(this.details.date, !this._isStockLoss());
Expand Down Expand Up @@ -371,7 +366,6 @@ function StockExitFormService(
StockExitForm.prototype.setServiceDistribution = function setServiceDistribution(service) {
this.details.entity_uuid = service.uuid;
this.details.flux_id = TO_SERVICE;
console.log('service:', service);
console.log('requisition:', service.requisition);

if (service.requisition) {
Expand All @@ -388,7 +382,6 @@ function StockExitFormService(
StockExitForm.prototype.setDepotDistribution = function setDepotDistribution(depot) {
this.details.entity_uuid = depot.uuid;
this.details.flux_id = TO_OTHER_DEPOT;
console.log('depot:', depot);
console.log('requisition:', depot.requisition);

if (depot.requisition) {
Expand Down Expand Up @@ -611,5 +604,15 @@ function StockExitFormService(
});
};

/**
* @function formatForExport
*
* @description
* Formats the grid rows for export.
*/
StockExitForm.prototype.formatRowsForExport = function formatRows(rows = []) {
return rows.map(row => row.formatForExport());
};

return StockExitForm;
}
25 changes: 0 additions & 25 deletions client/src/modules/stock/StockExitFormHelper.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,5 @@ function StockExitFormHelperService(moment, $q, $translate, bhConstants, Patient
});
};

/**
* @function formatRowsForExport
*
* @description this function will be apply to grid columns as filter for getting new columns
*
* @param {array} rows - refer to the grid data array
* @return {array} - return an array of array with value as an object in this format : { value : ... }
*/
service.formatRowsForExport = function formatRowsForExport(rows = []) {
return rows.map(row => {
const code = row.inventory?.code;
const description = row.inventory?.text;
const lot = row.lot?.label;
const price = row.inventory?.unit_cost;
const quantity = row.quantity?.quantity;
const type = row.quantity?.unit_type;
const available = row.inventory?.quantity;
const amount = (price && quantity) ? price * quantity : 0;
const expiration = (row.lot && row.lot.expiration_date)
? moment(row.lot.expiration_date).format(formatDB) : null;

return [code, description, lot, price, quantity, type, available, amount, expiration].map(value => ({ value }));
});
};

return service;
}
5 changes: 2 additions & 3 deletions client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ function StockExitController(

const exportation = new GridExportService(vm.gridOptions);

// runs validation and updates the messages
// runs validation and updates the messages for the user
vm.validate = () => {
vm.stockForm.validate();
vm.messages = vm.stockForm.messages();
console.log('vm.messages:', vm.messages);
};

vm.configureItem = function configureItem(row, lot) {
Expand All @@ -137,7 +136,7 @@ function StockExitController(
* @description export the content of the grid to csv.
*/
vm.exportGrid = () => {
exportation.exportToCsv('Stock_Exit_', exportation.defaultColumnFormatter, StockForm.formatRowsForExport);
exportation.exportToCsv('Stock_Exit_', exportation.defaultColumnFormatter, vm.stockForm.formatRowsForExport);
};

function onRegisterApi(gridApi) {
Expand Down

0 comments on commit fc6b8a2

Please sign in to comment.