Commit cb2d1c59 by Damien Moulard

ALC: display product price or prices

parent 2825333f
Pipeline #2110 passed with stage
in 1 minute 27 seconds
......@@ -264,7 +264,8 @@
padding: .5rem .5rem;
}
.supplier_package_qty {
.supplier_package_qty,
.supplier_price {
font-style: italic;
font-size: 1.3rem;
}
......
......@@ -31,7 +31,7 @@ var dbc = null,
var clicked_order_pill = null;
let userAgent = navigator.userAgent;
var timerId;
var timerId = null;
/* - UTILS */
......@@ -272,8 +272,8 @@ function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty,
purchase_package_qty_for_coverage *= coeff;
}
}
// return Round up to unit for all products
return Math.ceil(purchase_package_qty_for_coverage);
return Math.ceil(purchase_package_qty_for_coverage); // return Round up to unit for all products
}
function compute_and_affect_product_supplier_quantities(coeff, days) {
......@@ -282,22 +282,19 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
product
] of Object.entries(products)) {
if ('suppliersinfo' in product && product.suppliersinfo.length > 0) {
let purchase_qty_for_coverage = null;
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
const stock = product.qty_available;
const incoming_qty = product.incoming_qty;
const daily_conso = product.daily_conso;
purchase_package_qty_for_coverage = compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, daily_conso, days);
let purchase_package_qty_for_coverage = compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, daily_conso, days);
// Set qty to purchase for first supplier only
products[key].suppliersinfo[0].qty = purchase_package_qty_for_coverage;
}
}
}
/**
* Compute the qty to buy for each product, depending the coverage days.
* Set the computed qty for the first supplier only.
......@@ -1431,12 +1428,23 @@ function display_suppliers() {
});
}
/**
* Compute data to display in products table
*
* Package qties & prices are related to suppliers,
* so 1 product can have multiple values for these.
* In case of different values, display value under input in supplier column
*
* @param {Object} product
* @returns Object of computed data to add to product object
*/
function _compute_product_data(product) {
let item = {};
/* Supplier related data */
let purchase_qty = 0; // Calculate product's total purchase qty
let p_package_qties = []; // Look for differences in package qties
let p_price = [];
for (let p_supplierinfo of product.suppliersinfo) {
// Preset qty for input if product related to supplier: existing qty or null (null -> qty to be set, display an empty input)
......@@ -1451,6 +1459,7 @@ function _compute_product_data(product) {
// Store temporarily product package qties
p_package_qties.push(p_supplierinfo.package_qty);
p_price.push(p_supplierinfo.price);
}
item.purchase_qty = purchase_qty;
......@@ -1463,13 +1472,19 @@ function _compute_product_data(product) {
}
if (p_package_qties.length == 0 || !p_package_qties.every((val, i, arr) => val === arr[0])) {
// Don't display package qty if no supplierinf or if not all package qties are equals,
// Don't display package qty if no supplierinfo or if not all package qties are equals
item.package_qty = 'X';
} else {
// If all package qties are equals, display it
item.package_qty = p_package_qties[0];
}
if (p_price.length == 0 || !p_price.every((val, i, arr) => val === arr[0])) {
item.price = 'X';
} else {
item.price = p_price[0];
}
/* Coverage related data */
const coverage_days = (order_doc.coverage_days !== null) ? order_doc.coverage_days : 0;
let qty_not_covered = 0;
......@@ -1607,6 +1622,7 @@ function prepare_datatable_columns() {
let content = `<div id="${base_id}_cell_content" class="custom_cell_content">
<input type="number" class="product_qty_input" id="${base_id}_qty_input" min="-1" value=${data}>`;
// Add package qty & price data if they differ between suppliers
if (full.package_qty === 'X') {
let product_data = products.find(p => p.id == full.id);
......@@ -1617,6 +1633,16 @@ function prepare_datatable_columns() {
}
}
if (full.price === 'X') {
let product_data = products.find(p => p.id == full.id);
if (product_data !== undefined) {
let supplierinfo = product_data.suppliersinfo.find(psi => psi.supplier_id == supplier.id);
content += `<span class="supplier_price">Prix HT : ${supplierinfo.price} €</span>`;
}
}
content += `</div>`;
return content;
......@@ -1640,19 +1666,30 @@ function prepare_datatable_columns() {
});
columns.push({
data: "purchase_qty",
title: "Qté Achat",
data: "price",
title: "Prix HT",
className: "dt-body-center",
render: function (data) {
return (data === 'X') ? data : `${data} €`;
},
width: "4%"
});
columns.push({
data: "qty_not_covered",
title: "Besoin non couvert (qté)",
data: "purchase_qty",
title: "Qté Achat",
className: "dt-body-center",
width: "4%"
});
// Not in use for now
// columns.push({
// data: "qty_not_covered",
// title: "Besoin non couvert (qté)",
// className: "dt-body-center",
// width: "4%"
// });
columns.push({
data: "days_covered",
title: "Jours de couverture",
......@@ -1664,7 +1701,7 @@ function prepare_datatable_columns() {
title: ``,
className: "dt-body-center",
orderable: false,
render: function (data) {
render: function () {
return `<button type="button" class="btn--primary product_actions">Actions</button>`;
},
width: "4%"
......@@ -1811,16 +1848,18 @@ function display_products(params) {
.focus();
}
})
.on('click', 'tbody td .product_actions', function(e) {
.on('click', 'tbody td .product_actions', function() {
// Save / unsave selected row
const p_id = products_table.row($(this).closest('tr')).data().id;
const product = products.find(p => p.id == p_id);
let modal_product_actions = $('#templates #modal_product_actions');
modal_product_actions.find(".product_name").text(product.name);
modal_product_actions.find(".actual_stock_input").val(product.qty_available);
const product_can_be_archived = product.incoming_qty === 0;
if (product_can_be_archived == true) {
modal_product_actions.find('input[name="archive-action"]').prop("disabled", false);
modal_product_actions.find('input[name="archive-action"]').closest("label")
......@@ -1832,6 +1871,7 @@ function display_products(params) {
}
let product_price_action_template = $('#templates #product_price_action_template');
modal_product_actions.find(".product_prices_area").empty();
for (let supplierinfo of product.suppliersinfo) {
let supplier = suppliers_list.find(s => s.id == supplierinfo.supplier_id);
......@@ -2639,17 +2679,12 @@ $(document).ready(function() {
// Have to capture mousedown and mouseup events, instead of using only click event
// Indeed, capturing click only remove the ability to click to have focus on the input to type a number.
$(document).on("mousedown", '[type="number"]', function() {
const clicked = this;
qties_values[$(clicked).attr('id')] = $(clicked).val();
qties_values[$(this).attr('id')] = $(this).val();
});
$(document).on("mouseup", '[type="number"]', function() {
const clicked = this;
try {
if ($(clicked).val() != qties_values[$(clicked).attr('id')]) {
process_new_product_qty(clicked);
if ($(this).val() != qties_values[$(this).attr('id')]) {
process_new_product_qty(this);
}
} catch (err) {
console.log(err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment