Commit cc101100 by François C.

Fix eslint warning

parent 5b119348
Pipeline #1888 passed with stage
in 1 minute 32 seconds
...@@ -20,7 +20,7 @@ function init_faq() { ...@@ -20,7 +20,7 @@ function init_faq() {
} }
$(document).on('click', "#shift_exchange_btn", () => { $(document).on('click', "#shift_exchange_btn", () => {
goto('echange-de-services'); goto('echange-de-services');
}); });
$(document).on('click', '.accordion', function() { $(document).on('click', '.accordion', function() {
......
...@@ -68,8 +68,7 @@ function prepare_server_data(data) { ...@@ -68,8 +68,7 @@ function prepare_server_data(data) {
if (history_item.associate_registered == false || history_item.associate_registered == undefined) { if (history_item.associate_registered == false || history_item.associate_registered == undefined) {
history_item.associate_registered = ""; history_item.associate_registered = "";
} } else {
else {
if (partner_data.associated_partner_id != "False") { if (partner_data.associated_partner_id != "False") {
if (history_item.associate_registered==="partner") { if (history_item.associate_registered==="partner") {
history_item.associate_registered = partner_data.name; history_item.associate_registered = partner_data.name;
......
...@@ -20,7 +20,7 @@ function can_exchange_shifts() { ...@@ -20,7 +20,7 @@ function can_exchange_shifts() {
* @returns boolean * @returns boolean
*/ */
function should_select_makeup() { function should_select_makeup() {
return partner_data.makeups_to_do > 0 || (partner_data.makeups_to_do > 0 && partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False"); return partner_data.makeups_to_do > 0 || (partner_data.makeups_to_do > 0 && partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False");
} }
/** /**
...@@ -36,7 +36,7 @@ function add_or_change_shift(new_shift_id) { ...@@ -36,7 +36,7 @@ function add_or_change_shift(new_shift_id) {
+'&idPartner=' + partner_data.partner_id +'&idPartner=' + partner_data.partner_id
+ '&shift_type=' + partner_data.shift_type + '&shift_type=' + partner_data.shift_type
+ '&verif_token=' + partner_data.verif_token; + '&verif_token=' + partner_data.verif_token;
} else if(partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False") { } else if (partner_data.is_associated_people === "True" && block_actions_for_attached_people === "False") {
tData = 'idNewShift=' + new_shift_id tData = 'idNewShift=' + new_shift_id
+'&idPartner=' + partner_data.parent_id +'&idPartner=' + partner_data.parent_id
+ '&shift_type=' + partner_data.shift_type + '&shift_type=' + partner_data.shift_type
...@@ -101,10 +101,10 @@ function add_or_change_shift(new_shift_id) { ...@@ -101,10 +101,10 @@ function add_or_change_shift(new_shift_id) {
`Il est néanmoins possible que la requête ait abouti, ` + `Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`); `veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
// Refectch shifts anyway, if registration/exchange was still succesful // Refectch shifts anyway, if registration/exchange was still succesful
setTimeout(() => { setTimeout(() => {
load_partner_shifts(partner_data.concerned_partner_id) load_partner_shifts(partner_data.concerned_partner_id)
.then(init_shifts_list); .then(init_shifts_list);
}, 300); }, 300);
} }
}, },
......
...@@ -147,7 +147,7 @@ function prepare_shift_line_template(date_begin) { ...@@ -147,7 +147,7 @@ function prepare_shift_line_template(date_begin) {
shift_line_template.find(".shift_line_date").text(f_date_shift_start); shift_line_template.find(".shift_line_date").text(f_date_shift_start);
shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr", time_options)); shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr", time_options));
return shift_line_template; return shift_line_template;
} }
......
...@@ -130,72 +130,73 @@ function debounceFunction(func, delay = 1000) { ...@@ -130,72 +130,73 @@ function debounceFunction(func, delay = 1000) {
} }
/* - PRODUCTS */ /* - PRODUCTS */
var process_new_product_qty = function(input) { var process_new_product_qty = function(input) {
// Remove line coloring on input blur // Remove line coloring on input blur
const row = $(input).closest('tr'); const row = $(input).closest('tr');
row.removeClass('focused_line'); row.removeClass('focused_line');
let val = ($(input).val() == '') ? 0 : $(input).val(); let val = ($(input).val() == '') ? 0 : $(input).val();
const id_split = $(input).attr('id') const id_split = $(input).attr('id')
.split('_'); .split('_');
const prod_id = id_split[1]; const prod_id = id_split[1];
const supplier_id = id_split[3]; const supplier_id = id_split[3];
if (val == -1) {
let modal_end_supplier_product_association = $('#templates #modal_end_supplier_product_association');
const product = products.find(p => p.id == prod_id); if (val == -1) {
let modal_end_supplier_product_association = $('#templates #modal_end_supplier_product_association');
modal_end_supplier_product_association.find(".product_name").text(product.name); const product = products.find(p => p.id == prod_id);
const supplier = selected_suppliers.find(s => s.id == supplier_id);
modal_end_supplier_product_association.find(".supplier_name").text(supplier.display_name); modal_end_supplier_product_association.find(".product_name").text(product.name);
const supplier = selected_suppliers.find(s => s.id == supplier_id);
openModal( modal_end_supplier_product_association.find(".supplier_name").text(supplier.display_name);
modal_end_supplier_product_association.html(),
() => {
if (is_time_to('validate_end_supplier_product_association')) {
end_supplier_product_association(product, supplier);
}
},
'Valider',
false,
true,
() => {
// Reset value in input on cancel
const psi = product.suppliersinfo.find(psi_item => psi_item.supplier_id == supplier_id);
$(input).val(psi.qty); openModal(
modal_end_supplier_product_association.html(),
() => {
if (is_time_to('validate_end_supplier_product_association')) {
end_supplier_product_association(product, supplier);
} }
); },
} else { 'Valider',
val = parseFloat(val); false,
true,
() => {
// Reset value in input on cancel
const psi = product.suppliersinfo.find(psi_item => psi_item.supplier_id == supplier_id);
// If value is a number $(input).val(psi.qty);
if (!isNaN(val)) { }
// Save value );
save_product_supplier_qty(prod_id, supplier_id, val); } else {
val = parseFloat(val);
// Update row // If value is a number
const product = products.find(p => p.id == prod_id); if (!isNaN(val)) {
const new_row_data = prepare_datatable_data([product.id])[0]; // Save value
save_product_supplier_qty(prod_id, supplier_id, val);
products_table.row($(input).closest('tr')).data(new_row_data) // Update row
.draw(); const product = products.find(p => p.id == prod_id);
const new_row_data = prepare_datatable_data([product.id])[0];
debounceFunction(update_cdb_order); products_table.row($(input).closest('tr')).data(new_row_data)
display_total_values(); .draw();
} else {
$(input).val(''); debounceFunction(update_cdb_order);
} display_total_values();
} else {
$(input).val('');
} }
}
}; };
/** /**
* Add a product. * Add a product.
* *
* @returns -1 if validation failed, 0 otherwise * @returns -1 if validation failed, 0 otherwise
*/ */
function add_product() { function add_product() {
const user_input = $("#product_input").val(); const user_input = $("#product_input").val();
...@@ -258,6 +259,7 @@ function add_product() { ...@@ -258,6 +259,7 @@ function add_product() {
} }
function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, daily_conso, days) { function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, daily_conso, days) {
let purchase_qty_for_coverage = null; let purchase_qty_for_coverage = null;
purchase_qty_for_coverage = days * daily_conso - stock - incoming_qty + product.minimal_stock; purchase_qty_for_coverage = days * daily_conso - stock - incoming_qty + product.minimal_stock;
purchase_qty_for_coverage = (purchase_qty_for_coverage < 0) ? 0 : purchase_qty_for_coverage; purchase_qty_for_coverage = (purchase_qty_for_coverage < 0) ? 0 : purchase_qty_for_coverage;
...@@ -273,20 +275,21 @@ function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, ...@@ -273,20 +275,21 @@ function compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty,
function compute_and_affect_product_supplier_quantities(coeff, days) { function compute_and_affect_product_supplier_quantities(coeff, days) {
for (const [ for (const [
key, key,
product product
] of Object.entries(products)) { ] of Object.entries(products)) {
if ('suppliersinfo' in product && product.suppliersinfo.length > 0) { if ('suppliersinfo' in product && product.suppliersinfo.length > 0) {
let purchase_qty_for_coverage = null; let purchase_qty_for_coverage = null;
// Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne // Durée couverture produit = (stock + qté entrante + qté commandée ) / conso quotidienne
const stock = product.qty_available; const stock = product.qty_available;
const incoming_qty = product.incoming_qty; const incoming_qty = product.incoming_qty;
const daily_conso = product.daily_conso; const daily_conso = product.daily_conso;
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 purchase_package_qty_for_coverage = compute_purchase_qty_for_coverage(product, coeff, stock, incoming_qty, daily_conso, days);
products[key].suppliersinfo[0].qty = purchase_package_qty_for_coverage; // Set qty to purchase for first supplier only
} products[key].suppliersinfo[0].qty = purchase_package_qty_for_coverage;
}
} }
} }
...@@ -297,9 +300,10 @@ function compute_and_affect_product_supplier_quantities(coeff, days) { ...@@ -297,9 +300,10 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
* Set the computed qty for the first supplier only. * Set the computed qty for the first supplier only.
*/ */
function compute_products_coverage_qties() { function compute_products_coverage_qties() {
return new Promise((resolve) => { return new Promise((resolve) => {
const pc_adjust = $('#percent_adjust_input').val(); const pc_adjust = $('#percent_adjust_input').val();
let coeff = 1; let coeff = 1;
if (!isNaN(parseFloat(pc_adjust))) { if (!isNaN(parseFloat(pc_adjust))) {
coeff = (1 + parseFloat(pc_adjust) /100); coeff = (1 + parseFloat(pc_adjust) /100);
} }
...@@ -308,20 +312,20 @@ function compute_products_coverage_qties() { ...@@ -308,20 +312,20 @@ function compute_products_coverage_qties() {
compute_and_affect_product_supplier_quantities(coeff, order_doc.coverage_days); compute_and_affect_product_supplier_quantities(coeff, order_doc.coverage_days);
} else if (order_doc.targeted_amount != null) { } else if (order_doc.targeted_amount != null) {
const small_step = 0.1, const small_step = 0.1,
max_iter = 182; // Assume that no more than 1/2 year coverage is far enough max_iter = 182; // Assume that no more than 1/2 year coverage is far enough
let go_on = true, let go_on = true,
iter = 0, iter = 0,
days = 1, days = 1,
step = 1; step = 1;
//Let's compute the nearst amount, by changing days quantity //Let's compute the nearst amount, by changing days quantity
while(go_on == true && iter < max_iter) { while (go_on == true && iter < max_iter) {
order_total_value = 0; order_total_value = 0;
compute_and_affect_product_supplier_quantities(coeff, days); compute_and_affect_product_supplier_quantities(coeff, days);
_compute_total_values_by_supplier(); _compute_total_values_by_supplier();
for (let supplier of selected_suppliers) { for (let supplier of selected_suppliers) {
order_total_value += supplier.total_value; order_total_value += supplier.total_value;
} }
let order_total_value_f = parseFloat(order_total_value), let order_total_value_f = parseFloat(order_total_value),
targeted_amount_f = parseFloat(order_doc.targeted_amount); targeted_amount_f = parseFloat(order_doc.targeted_amount);
...@@ -343,7 +347,7 @@ function compute_products_coverage_qties() { ...@@ -343,7 +347,7 @@ function compute_products_coverage_qties() {
iter++; iter++;
} }
} }
resolve(); resolve();
}); });
...@@ -1740,94 +1744,94 @@ function display_products(params) { ...@@ -1740,94 +1744,94 @@ function display_products(params) {
row.addClass('focused_line'); row.addClass('focused_line');
}); });
// Manage data on inputs blur // Manage data on inputs blur
$('#products_table') $('#products_table')
.on('blur', 'tbody td .product_qty_input', function () { .on('blur', 'tbody td .product_qty_input', function () {
process_new_product_qty(this); process_new_product_qty(this);
}) })
.on('keypress', 'tbody td .product_qty_input', function(e) { .on('keypress', 'tbody td .product_qty_input', function(e) {
// Validate on Enter pressed // Validate on Enter pressed
if (e.which == 13) { if (e.which == 13) {
$(this).blur(); $(this).blur();
} }
}) })
.on('keydown', 'tbody td .product_qty_input', function(e) { .on('keydown', 'tbody td .product_qty_input', function(e) {
if (e.which == 38) { if (e.which == 38) {
e.preventDefault(); e.preventDefault();
// On arrow up pressed, focus next row input // On arrow up pressed, focus next row input
let next_input = $(this).closest("tr") let next_input = $(this).closest("tr")
.prev() .prev()
.find(".product_qty_input"); .find(".product_qty_input");
next_input.focus(); next_input.focus();
// Scroll to a position where the target input is not hidden by the sticky suppliers container // Scroll to a position where the target input is not hidden by the sticky suppliers container
const suppliers_container_top_offset = const suppliers_container_top_offset =
$("#suppliers_container").offset().top $("#suppliers_container").offset().top
- $(window).scrollTop() - $(window).scrollTop()
+ $("#suppliers_container").outerHeight(); + $("#suppliers_container").outerHeight();
const next_input_top_offset = next_input.offset().top - $(window).scrollTop(); const next_input_top_offset = next_input.offset().top - $(window).scrollTop();
if (next_input_top_offset < suppliers_container_top_offset) { if (next_input_top_offset < suppliers_container_top_offset) {
window.scrollTo({ window.scrollTo({
top: $(window).scrollTop() - $("#suppliers_container").outerHeight() top: $(window).scrollTop() - $("#suppliers_container").outerHeight()
}); });
}
} else if (e.which == 40) {
e.preventDefault();
// On arrow down pressed, focus previous row input
$(this).closest("tr")
.next()
.find(".product_qty_input")
.focus();
} else if (e.which == 13) {
e.preventDefault();
// On enter pressed, focus previous row input
$(this).closest("tr")
.next()
.find(".product_qty_input")
.focus();
} }
} else if (e.which == 40) { })
e.preventDefault(); .on('click', 'tbody td .product_actions', function(e) {
// On arrow down pressed, focus previous row input
$(this).closest("tr")
.next()
.find(".product_qty_input")
.focus();
} else if (e.which == 13) {
e.preventDefault();
// On enter pressed, focus previous row input
$(this).closest("tr")
.next()
.find(".product_qty_input")
.focus();
}
})
.on('click', 'tbody td .product_actions', function(e) {
// Save / unsave selected row // Save / unsave selected row
const p_id = products_table.row($(this).closest('tr')).data().id; const p_id = products_table.row($(this).closest('tr')).data().id;
const product = products.find(p => p.id == p_id); const product = products.find(p => p.id == p_id);
let modal_product_actions = $('#templates #modal_product_actions'); let modal_product_actions = $('#templates #modal_product_actions');
modal_product_actions.find(".product_name").text(product.name); modal_product_actions.find(".product_name").text(product.name);
const product_can_be_archived = product.incoming_qty === 0; const product_can_be_archived = product.incoming_qty === 0;
if (product_can_be_archived == true) { 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"]').prop("disabled", false);
modal_product_actions.find('input[name="archive-action"]').closest("label") modal_product_actions.find('input[name="archive-action"]').closest("label")
.removeClass("checkbox_action_disabled"); .removeClass("checkbox_action_disabled");
} else { } else {
modal_product_actions.find('input[name="archive-action"]').prop("disabled", true); modal_product_actions.find('input[name="archive-action"]').prop("disabled", true);
modal_product_actions.find('input[name="archive-action"]').closest("label") modal_product_actions.find('input[name="archive-action"]').closest("label")
.addClass("checkbox_action_disabled"); .addClass("checkbox_action_disabled");
} }
openModal( openModal(
modal_product_actions.html(), modal_product_actions.html(),
() => { () => {
if (is_time_to('validate_product_actions')) { if (is_time_to('validate_product_actions')) {
commit_actions_on_product(product, modal.find('input')); commit_actions_on_product(product, modal.find('input'));
} }
}, },
'Valider', 'Valider',
false false
); );
modal.find('input[name="minimal_stock"]').val(product.minimal_stock); modal.find('input[name="minimal_stock"]').val(product.minimal_stock);
}); });
// Associate product to supplier on click on 'X' in the table // Associate product to supplier on click on 'X' in the table
$('#products_table').on('click', 'tbody .product_not_from_supplier', function () { $('#products_table').on('click', 'tbody .product_not_from_supplier', function () {
...@@ -2260,15 +2264,15 @@ $(document).ready(function() { ...@@ -2260,15 +2264,15 @@ $(document).ready(function() {
order_doc.coverage_days = days_val; order_doc.coverage_days = days_val;
order_doc.targeted_amount = amount_val; order_doc.targeted_amount = amount_val;
compute_products_coverage_qties() compute_products_coverage_qties()
.then(() => { .then(() => {
debounceFunction(update_cdb_order); debounceFunction(update_cdb_order);
update_main_screen(); update_main_screen();
}) });
} else { } else {
$("#coverage_days_input").val(order_doc.coverage_days || ''); $("#coverage_days_input").val(order_doc.coverage_days || '');
$('#targeted_amount_input').val(order_doc.targeted_amount || ''); $('#targeted_amount_input').val(order_doc.targeted_amount || '');
alert("Ni le nombre de jours de couverture, ni le montant à atteindre sont correctement renseignés") alert("Ni le nombre de jours de couverture, ni le montant à atteindre sont correctement renseignés");
} }
} }
...@@ -2324,11 +2328,11 @@ $(document).ready(function() { ...@@ -2324,11 +2328,11 @@ $(document).ready(function() {
check_products_data() check_products_data()
.then(() => { .then(() => {
compute_products_coverage_qties() compute_products_coverage_qties()
.then(() => { .then(() => {
update_main_screen(); update_main_screen();
debounceFunction(update_cdb_order); debounceFunction(update_cdb_order);
closeModal(); closeModal();
}) });
}); });
} }
...@@ -2606,21 +2610,23 @@ $(document).ready(function() { ...@@ -2606,21 +2610,23 @@ $(document).ready(function() {
// Indeed, capturing click only remove the ability to click to have focus on the input to type a number. // 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() { $(document).on("mousedown", '[type="number"]', function() {
const clicked = this; const clicked = this;
qties_values[$(clicked).attr('id')] = $(clicked).val(); qties_values[$(clicked).attr('id')] = $(clicked).val();
}); });
$(document).on("mouseup", '[type="number"]', function() { $(document).on("mouseup", '[type="number"]', function() {
const clicked = this; const clicked = this;
try { try {
if ($(clicked).val() != qties_values[$(clicked).attr('id')]) { if ($(clicked).val() != qties_values[$(clicked).attr('id')]) {
process_new_product_qty(clicked); process_new_product_qty(clicked);
} }
} catch(err) { } catch (err) {
console.log(err) console.log(err);
} }
}); });
} }
} else { } else {
$('#not_connected_content').show(); $('#not_connected_content').show();
} }
......
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