Skip to content

Commit

Permalink
fix(entry stock): Fix somes issues about stok entry
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Oct 19, 2017
1 parent 6335db4 commit f0cc43d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ SESS_SECRET='XopEn BlowFISH'
SESS_RESAVE=0
SESS_UNSET='destroy'

# LOG_LEVEL='warn'
LOG_LEVEL='debug'
LOG_LEVEL='warn'
# LOG_LEVEL='debug'

UPLOAD_DIR='client/upload'

Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"ORIGINS" : "Lots Origins",
"ORIGIN_DOCUMENT" : "Origin Document",
"PATIENT_DISTRIBUTION" : "Patient Distribution",
"PURCHASE_DESCRIPTION" : "Purchaser order description",
"SERVICE_DISTRIBUTION" : "Service Distribution",
"DEPOT_DISTRIBUTION" : "Depot Distribution",
"LOSS_DISTRIBUTION" : "Stock Loss",
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"ORIGINS" : "Origines des lots",
"ORIGIN_DOCUMENT" : "Document de l'origine",
"PATIENT_DISTRIBUTION" : "Distribution au Patient",
"PURCHASE_DESCRIPTION" : "Description pour order d'achat",
"SERVICE_DISTRIBUTION" : "Distribution au Service",
"DEPOT_DISTRIBUTION" : "Distribution au depot",
"LOSS_DISTRIBUTION" : "Perte de Stock",
Expand Down
56 changes: 36 additions & 20 deletions client/src/modules/stock/entry/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function StockEntryController(
vm.removeItem = removeItem;
vm.selectEntryType = selectEntryType;
vm.setInitialized = setInitialized;
vm.buildStockLine = buildStockLine;
vm.setLots = setLots;
vm.submit = submit;
vm.changeDepot = changeDepot;
Expand Down Expand Up @@ -174,10 +175,10 @@ function StockEntryController(
.catch(Notify.handleError);
}

// ============================ Modals ================================
// find purchase
// pop up a modal to let user find a purchase order
function findPurchase() {
initSelectedEntity('Stock Entry Purchase');
var description = $translate.instant('STOCK.PURCHASE_DESCRIPTION');
initSelectedEntity(description);

StockModal.openFindPurchase()
.then(function (purchase) {
Expand All @@ -196,7 +197,8 @@ function StockEntryController(

// find transfer
function findTransfer() {
initSelectedEntity();
var description = $translate.instant('STOCK.RECEPTION_DESCRIPTION');
initSelectedEntity(description);

StockModal.openFindTansfer({ depot_uuid: vm.depot.uuid })
.then(function (transfers) {
Expand All @@ -208,8 +210,8 @@ function StockEntryController(
};

vm.reference = transfers[0].documentReference;
vm.movement.description = $translate.instant('STOCK.RECEPTION_DESCRIPTION');
populate(transfers);
vm.hasValidInput = hasValidInput();
})
.catch(Notify.handleError);
}
Expand Down Expand Up @@ -240,11 +242,21 @@ function StockEntryController(
item.code = inventory.code;
item.inventory_uuid = inventory.uuid;
item.label = inventory.label;
item.unit_cost = items[index].unit_price;
item.unit_cost = items[index].unit_price || items[index].unit_cost; // transfer comes with unit_cost
item.quantity = items[index].quantity;
item.cost = item.quantity * item.unit_cost;
item.expiration_date = new Date();

if(vm.movement.entity.type === 'transfer_reception') {
item.lots.push({
isValid: true,
lot : items[index].label,
quantity : item.quantity,
expiration_date : new Date(items[index].expiration_date),
uuid : items[index].uuid,
});
}

setInitialized(item);
});
}
Expand Down Expand Up @@ -299,6 +311,7 @@ function StockEntryController(
return data.reduce(function (current, line) {
return line.lots.map(function (lot) {
return {
uuid : lot.uuid || null,
label: lot.lot,
initial_quantity: lot.quantity,
quantity: lot.quantity,
Expand Down Expand Up @@ -345,7 +358,7 @@ function StockEntryController(
date: vm.movement.date,
description: vm.movement.description,
flux_id: bhConstants.flux.FROM_INTEGRATION,
user_id: Session.user.id,
user_id: vm.stockForm.details.user_id,
};

var entry = {
Expand All @@ -369,7 +382,7 @@ function StockEntryController(
date: vm.movement.date,
description: vm.movement.description,
flux_id: bhConstants.flux.FROM_DONATION,
user_id: Session.user.id,
user_id: vm.stockForm.details.user_id,
};

/*
Expand All @@ -379,7 +392,7 @@ function StockEntryController(
TODO: add a donor management module
*/
movement.lots = processLotsFromStore(vm.stockForm.store.data, Uuid());
movement.lots = processLotsFromStore(vm.stockForm.store.data, movement.entity_uuid);

return Stock.stocks.create(movement)
.then(function (document) {
Expand All @@ -397,20 +410,12 @@ function StockEntryController(
to_depot: vm.depot.uuid,
document_uuid: vm.movement.entity.instance.document_uuid,
date: vm.movement.date,
description: vm.movement.entity.instance.description,
description: vm.movement.description,
isExit: false,
user_id: Session.user.id,
user_id: vm.stockForm.details.user_id,
};

var lots = vm.stockForm.store.data.map(function (row) {
return {
uuid: row.lot_uuid,
quantity: row.lots[0].quantity,
unit_cost: row.unit_cost,
};
});

movement.lots = lots;
movement.lots = processLotsFromStore(vm.stockForm.store.data, null);

return Stock.movements.create(movement)
.then(function (document) {
Expand All @@ -429,5 +434,16 @@ function StockEntryController(
});
}

function buildStockLine(line) {
var inventory = inventoryStore.get(line.inventory_uuid);
line.code = inventory.code;
line.label = inventory.label;
line.unit_cost = inventory.price;
line.quantity = 0;
line.cost = line.quantity * line.unit_cost;
line.expiration_date = new Date();
setInitialized(line);
}

startup();
}
2 changes: 1 addition & 1 deletion client/src/modules/stock/entry/modals/lots.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
type="number"
ng-model="$ctrl.stockLine.quantity"
ng-model-options="{ 'debounce' : { 'default' : 150, 'blur' : 0 }}"
ng-change="$ctrl.handleChange($ctrl.stockLine)"
ng-change="$ctrl.checkAll()"
min="0">
</div>

Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/entry/modals/lots.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function StockDefineLotsModalController(Instance, Notify, uiGridConstants, Data,
vm.cancel = cancel;
vm.addLot = addLot;
vm.checkLine = checkLine
vm.checkAll = checkAll;
vm.removeLot = removeLot;

function init() {
Expand Down
6 changes: 3 additions & 3 deletions client/src/modules/stock/entry/templates/code.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div ng-if="!row.entity._initialised">
<input
class="form-control"
ng-model="row.entity.inventory"
ng-model="row.entity.inventory_uuid"
typeahead-editable="false"
typeahead-append-to-body="true"
uib-typeahead="item as item for item in grid.appScope.inventories | filter:$viewValue | limitTo:8"
uib-typeahead="item.uuid as item for item in grid.appScope.inventories | filter:$viewValue | limitTo:8"
typeahead-template-url="/modules/templates/inventoryItems.tmpl.html"
typeahead-on-select="grid.appScope.configureItem(row.entity)">
typeahead-on-select="grid.appScope.buildStockLine(row.entity)">
</div>
<div ng-if="row.entity._initialised">
{{ row.entity.code }}
Expand Down

0 comments on commit f0cc43d

Please sign in to comment.