Skip to content

Commit

Permalink
feat(stock exit) show sold out inventory
Browse files Browse the repository at this point in the history
closes #4381
  • Loading branch information
jeremielodi committed May 4, 2020
1 parent 678ac96 commit 0d03f17
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 6 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 @@ -267,6 +267,7 @@
"ALL": "All",
"ALL_EMPLOYEES": "All Employees",
"ALL_GENDER": "All Genders",
"SEE_ALL" : "See all",
"AMOUNT": "Amount",
"AMOUNT_PAID" : "Amount Paid",
"ARTICLES":"Articles",
Expand Down
2 changes: 2 additions & 0 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"ENTRY_TRANSFER" : "Transfer",
"TYPE_VALUE" : "Stock value",
"TYPE_QUANTITY" : "Stock quantity",
"SOLD_OUT_WARNING" : "Alert : there are {{total}} products out of stock",
"AND_MORE" : "... and {{left}} more",
"ERRORS" : {
"NO_ROWS" : "Must have at least one row in the grid.",
"MISSING_LOT_NAME" : "Missing Lot Identifier",
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 @@ -267,6 +267,7 @@
"ALL_EMPLOYEES": "Tous les employés",
"ALL_GENDER": "Tous les genres",
"ALL": "Tous",
"SEE_ALL" : "Tout voir",
"AMOUNT": "Montant",
"AMOUNT_PAID" : "Montant Payé",
"ARTICLES":"Articles",
Expand Down
2 changes: 2 additions & 0 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"ENTRY_TRANSFER" : "Transfert",
"TYPE_VALUE" : "Valeur de stock",
"TYPE_QUANTITY" : "Quantité de stock",
"SOLD_OUT_WARNING" : "Alert : il y a {{total}} produits en rupture de stock",
"AND_MORE" : "... et {{left}} autres",
"ERRORS" : {
"NO_ROWS" : "Vous devez avoir au moins une ligne dans le grid.",
"MISSING_LOT_NAME" : "Identifiant de lot manquant",
Expand Down
43 changes: 43 additions & 0 deletions client/src/modules/stock/exit/exit.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,49 @@
</div>
</div>
</div>

<div class="col-xs-12 col-md-6 panel-default">

<table
ng-show = "StockCtrl.soldOutInventories.length > 0"
class="table table-condensed table-bordered">
<thead>
<tr>
<th>
<span class="text-danger"
translate-values="{ total : StockCtrl.soldOutInventories.length }"
translate="{{ 'STOCK.SOLD_OUT_WARNING' }}">
</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "inventory in StockCtrl.soldOutInventories | limitTo : 5">
<td>{{inventory.text}} ({{inventory.stock_out_date}})</td>
</tr>

<tr>
<td>

<span class="text-danger"
ng-show="(StockCtrl.soldOutInventories.length - 5) > 0"
translate-values="{ left : (StockCtrl.soldOutInventories.length - 5)}"
translate="{{ 'STOCK.AND_MORE' }}">
</span>

<a ui-sref= "stockInventories({ filters : [
{ key : 'period', value : 'allTime'},
{ key : 'includeEmptyLot', value : 1 },
{ key : 'depot_uuid', value : StockCtrl.depot.uuid, displayValue: StockCtrl.depot.text, cacheable:false },
{ key : 'status', value : 'sold_out', displayValue: 'STOCK.STATUS.SOLD_OUT', cacheable:false }
]})"translate>FORM.LABELS.SEE_ALL</a>
</td>
</tr>
</tbody>

</table>

</div>
</div>

<!-- not available messages -->
Expand Down
20 changes: 20 additions & 0 deletions client/src/modules/stock/exit/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function StockExitController(
vm.movement = {};
vm.gridApi = {};
vm.selectedLots = [];
vm.soldOutInventories = [];
vm.reset = reset;
vm.ROW_ERROR_FLAG = bhConstants.grid.ROW_ERROR_FLAG;

Expand All @@ -41,6 +42,7 @@ function StockExitController(
vm.onChangeDepot = depot => {
vm.depot = depot;
loadInventories(vm.depot);
stockOut();
};

// bind methods
Expand Down Expand Up @@ -249,6 +251,7 @@ function StockExitController(
date : new Date(),
entity : {},
};
stockOut();
}

function loadInventories(depot) {
Expand Down Expand Up @@ -628,5 +631,22 @@ function StockExitController(
.catch(Notify.handleError);
}

/**
* @function stockOut
* get sold out inventories for a depot
*/
function stockOut() {
if (!vm.depot) return;
Stock.inventories.read(null, {
status : 'sold_out',
depot_uuid : vm.depot.uuid,
}).then(inventories => {
vm.soldOutInventories = inventories;
inventories.forEach(inventory => {
inventory.stock_out_date = moment(inventory.stock_out_date).fromNow();
});
}).catch(Notify.handleError);
}

startup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<li>
<a data-method="view-stock-lot" href
ui-sref="stockInventories({ filters : [
{ key : 'period', value : 'allTime', includeEmptyLot: 0 },
{ key : 'period', value : 'allTime' },
{ key : 'includeEmptyLot', value : 0 },
{ key : 'depot_uuid', value : row.entity.depot_uuid, displayValue: row.entity.depot_text },
{ key : 'inventory_uuid', value : row.entity.inventory_uuid, displayValue: row.entity.text }]})">
<i class="fa fa-cart-plus"></i> <span translate>REPORT.VIEW_ITEM_STOCK</span>
Expand Down
1 change: 1 addition & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ exports.configure = function configure(app) {
// stock management API
app.post('/stock/lots/movements', stock.createMovement);
app.get('/stock/lots/movements', stock.listLotsMovements);

app.post('/stock/lots', stock.createStock);
app.get('/stock/lots', stock.listLots);
app.get('/stock/lots/origins', stock.listLotsOrigins);
Expand Down
33 changes: 28 additions & 5 deletions server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,35 @@ function getLotsOrigins(depotUuid, params) {
return getLots(sql, params);
}

/**
* @function lastStockMovementDate
* get the last movement for an inventory
*/
function lastStockMovementDate(params) {
const { inventoryUuid, depotUuid } = params;
const sql = `
SELECT m.date
FROM stock_movement m
JOIN lot l ON l.uuid = m.lot_uuid
WHERE m.depot_uuid = ? AND l.inventory_uuid = ?
ORDER BY m.created_at DESC
LIMIT 1
`;
return db.one(sql, [db.bid(depotUuid), db.bid(inventoryUuid)]);
}

/**
* Stock Management Processing
*/
function stockManagementProcess(inventories) {
async function stockManagementProcess(inventories) {
const current = moment();
let CM;
let Q;
let CM_NOT_ZERO;
let delay;

return inventories.map((inventory) => {
for (let i = 0; i < inventories.length; i++) {
const inventory = inventories[i];
Q = inventory.quantity; // the quantity
CM = inventory.avg_consumption; // consommation mensuelle
CM_NOT_ZERO = !CM ? 1 : CM;
Expand All @@ -361,6 +379,12 @@ function stockManagementProcess(inventories) {

if (Q <= 0) {
inventory.status = 'sold_out';
// eslint-disable-next-line no-await-in-loop
const mvt = await lastStockMovementDate({
inventoryUuid : inventory.inventory_uuid,
depotUuid : inventory.depot_uuid,
});
inventory.stock_out_date = mvt.date;
} else if (Q > 0 && Q <= inventory.S_SEC) {
inventory.status = 'security_reached';
} else if (Q > inventory.S_SEC && Q <= inventory.S_MIN) {
Expand All @@ -380,9 +404,8 @@ function stockManagementProcess(inventories) {

delay = moment(new Date(inventory.expiration_date)).diff(current);
inventory.delay_expiration = moment.duration(delay).humanize();

return inventory;
});
}
return inventories;
}

/**
Expand Down

0 comments on commit 0d03f17

Please sign in to comment.