Commit 6dd3b288 by Damien Moulard

REC: update qty during price update, with password

parent 129d2267
Pipeline #2291 passed with stage
in 1 minute 25 seconds
......@@ -305,6 +305,9 @@ tr.odd td.row_product_no_qty {
.product_qty_cell:hover {
background-color: #e7e9ed;
}
td.row_product_no_qty.product_qty_cell:hover {
background-color: #db9129;
}
/* Accordion style */
......
......@@ -32,7 +32,8 @@ var reception_status = null,
barcodes = null, // Barcodes stored locally
priceToWeightIsCorrect = true,
suppliers_products = [], // All products of current order(s) supplier(s)
products_to_add = []; // Products to add to order
products_to_add = [], // Products to add to order
re_editing_qty = false; // During prices edition, edit qty mode enabled
var dbc = null,
sync = null,
......@@ -612,7 +613,7 @@ function initLists() {
{
data:"product_qty",
title: qty_title_tooltip,
className:"dt-head-center dt-body-center",
className: (reception_status == "qty_valid") ? "dt-head-center dt-body-center product_qty_cell" : "dt-head-center dt-body-center",
width: "5%",
// visible: (reception_status == "False"),
render: function (data, type, full) {
......@@ -655,17 +656,30 @@ function initLists() {
}
];
table_to_process_ordering = [
[
0,
"asc"
]
];
// For grouped orders, order first by number of order, then by product id
if (is_grouped_order()) {
table_to_process_ordering.push(
[
1,
"asc"
]
)
}
// Init table for to_process content
table_to_process = $('#table_to_process').DataTable({
data: list_to_process,
columns: columns_to_process,
rowId : "product_id.0",
order: [
[
0,
"asc"
]
],
order: table_to_process_ordering,
scrollY: "33vh",
scrollCollapse: true,
paging: false,
......@@ -904,15 +918,65 @@ function initLists() {
});
$('#table_to_process tbody').on('click', '.product_qty_cell', function () {
// Prevent editing mutiple lines at a time
if (editing_product == null) {
let pswd = prompt('Mot de passe requis pour éditer la quantité de ce produit');
if (pswd == update_qty_pswd) {
// Password ok, edit product qty
let row = table_to_process.row($(this).parents('tr'));
let data = row.data();
// Product goes to editing
editing_origin = "to_process";
re_editing_qty = true;
setLineEdition(data);
remove_from_toProcess(row, data);
document.getElementById('search_input').value = '';
$('table.dataTable').DataTable()
.search('')
.draw();
} else if (pswd == null) {
return;
} else {
alert('Mauvais mot de passe !');
}
} else {
alert("Il y a déjà un produit dans la zone d'édition. Terminez d'abord d'éditer ce produit.")
}
});
$('#table_processed tbody').on('click', '.product_qty_cell', function () {
// Prevent editing mutiple lines at a time
if (editing_product == null) {
let pswd = prompt('Mot de passe requis pour éditer la quantité de ce produit');
if (pswd == update_qty_pswd) {
// Password ok, edit product qty
let row = table_processed.row($(this).parents('tr'));
let data = row.data();
// Product goes to editing
editing_origin = "processed";
re_editing_qty = true;
setLineEdition(data);
remove_from_processed(row, data);
console.log('clicked'); //
document.getElementById('search_input').value = '';
$('table.dataTable').DataTable()
.search('')
.draw();
} else if (pswd == null) {
return;
} else {
alert('Mauvais mot de passe !');
}
} else {
alert("Il y a déjà un produit dans la zone d'édition. Terminez d'abord d'éditer ce produit.")
}
});
}
......@@ -1095,23 +1159,23 @@ function set_supplier_shortage(row, product, from_processed = false) {
/* EDITION */
// Set edition
// Set edition area
function setLineEdition(product) {
editing_product = product;
// name
document.getElementById('product_name').innerHTML = editing_product.product_id[1];
// intput
if (reception_status == "qty_valid")
document.getElementById('edition_input').value = editing_product.price_unit;
else
if (reception_status == 'False' || re_editing_qty === true)
document.getElementById('edition_input').value = editing_product.product_qty;
else
document.getElementById('edition_input').value = editing_product.price_unit;
document.getElementById("edition_input").focus();
// uom
if (editing_product.product_uom[0] == 1) { // Unit
if (reception_status == 'False') {
if (reception_status == 'False' || re_editing_qty === true) {
document.getElementById('product_uom').innerHTML = ' unité(s)';
$('#edition_input').attr('type', 'number')
.attr('step', 1)
......@@ -1123,7 +1187,7 @@ function setLineEdition(product) {
.attr('max', 9999);
}
} else if (editing_product.product_uom[0] == 21) { // kg
if (reception_status == 'False') {
if (reception_status == 'False' || re_editing_qty === true) {
document.getElementById('product_uom').innerHTML = ' kg';
$('#edition_input').attr('type', 'number')
.attr('step', 0.001)
......@@ -1136,6 +1200,12 @@ function setLineEdition(product) {
}
}
// If editing qty during prices edition
if (re_editing_qty === true) {
document.getElementById('edition_header').innerHTML = "Ré-éditer la quantité";
document.getElementById('edition_input_label').innerHTML = "Qté";
}
// Make edition area blink when edition button clicked
container_edition.classList.add('blink_me');
}
......@@ -1149,6 +1219,13 @@ function clearLineEdition() {
document.getElementById('edition_input').value = null;
document.getElementById('search_input').focus();
document.getElementById('product_uom').innerHTML = '';
if (re_editing_qty === true) {
document.getElementById('edition_header').innerHTML = "Editer les prix";
document.getElementById('edition_input_label').innerHTML = "Prix unit.";
re_editing_qty = false;
}
}
/**
......@@ -1173,6 +1250,57 @@ function editProductInfo (productToEdit, value = null, batch = false) {
newValue = isFinite(newValue) ? newValue : 0;
}
// Particular process in case of qty reedition during prices update
if (re_editing_qty === true) {
// Look for product in product's order first step data
let previous_step_index = -1;
for (let i = 0; i < orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"].length; i++) {
if (
orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"][i].id
===
productToEdit.id
) {
previous_step_index = i;
break;
}
}
if (previous_step_index === -1) {
// Product qty hasn't been updated yet: add to first step data
productToEdit.old_qty = productToEdit.product_qty;
productToEdit.product_qty = newValue;
productToEdit.product_qty_package = 1;
productToEdit.package_qty = productToEdit.product_qty;
orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"].push(productToEdit)
} else {
productToEdit.product_qty = newValue;
productToEdit.package_qty = productToEdit.product_qty;
// Product qty has been updated before, update first step data
orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"][previous_step_index].product_qty = newValue;
orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"][previous_step_index].package_qty = newValue;
}
/* Send request to server to update a single product */
updateType = "qty_valid";
send([productToEdit]);
// Update temp couchdb order
update_distant_order(productToEdit.id_po);
// Put back product in its original list
if (editing_origin === "to_process") {
add_to_toProcess(productToEdit);
} else if (editing_origin === "processed") {
add_to_processed(productToEdit);
}
return true;
}
// addition mode = weight is directly added from scanned product
$.each(list_processed, function(i, e) {
if (
......@@ -1452,8 +1580,14 @@ function data_validation() {
});
}
// Send the request to the server
function send() {
/**
* Send the request to update order(s) data
*
* @param {Array} given_products If set, only update these products.
* If no given products, we're in the regular process, ie the end of a reception.
* Else, we're in the middle of a reception, so we'll skip some parts.
*/
function send(given_products = []) {
try {
// Loading on
openModal();
......@@ -1470,15 +1604,19 @@ function send() {
update_data.orders[order_id] = {'po' : []};
}
has_given_products = given_products.length > 0;
// If given products, update these only, else update global updatedProducts list
products_to_update = has_given_products === true ? given_products : updatedProducts;
// for each updated product, add it to its order list
for (i in updatedProducts) {
for (i in products_to_update) {
/* ---> The following part concerns products found in different orders */
if ('other_orders_data' in updatedProducts[i]) {
if ('other_orders_data' in products_to_update[i]) {
// for each other order of product
for (other_order_data of updatedProducts[i].other_orders_data) {
for (other_order_data of products_to_update[i].other_orders_data) {
// Make a clone (deep copy) of the product object
let product_copy = $.extend(true, {}, updatedProducts[i]);
let product_copy = $.extend(true, {}, products_to_update[i]);
// Set correct order line id for this product
product_copy.id = other_order_data.id_product;
......@@ -1487,30 +1625,30 @@ function send() {
if (reception_status == 'False') {
// Reset initial qties in respective orders
product_copy.old_qty = other_order_data.initial_qty;
for (j in orders[updatedProducts[i].id_po]['updated_products']) {
if (orders[updatedProducts[i].id_po]['updated_products'][j].product_id[0]
for (j in orders[products_to_update[i].id_po]['updated_products']) {
if (orders[products_to_update[i].id_po]['updated_products'][j].product_id[0]
== product_copy.product_id[0]) {
orders[updatedProducts[i].id_po]['updated_products'][j].old_qty -= other_order_data.initial_qty;
orders[products_to_update[i].id_po]['updated_products'][j].old_qty -= other_order_data.initial_qty;
break;
}
}
if (product_copy.product_uom[0] == 21 && updatedProducts[i].product_qty > 0.1) { // kg
if (product_copy.product_uom[0] == 21 && products_to_update[i].product_qty > 0.1) { // kg
// Add minimum qty in other orders
product_copy.product_qty_package = 1;
product_copy.package_qty = 0.1;
product_copy.product_qty = 0.1;
// Remove this qty from first order
updatedProducts[i].package_qty -= 0.1;
updatedProducts[i].product_qty -= 0.1;
} else if (product_copy.product_uom[0] == 1 && updatedProducts[i].product_qty > 1) { // Unit
products_to_update[i].package_qty -= 0.1;
products_to_update[i].product_qty -= 0.1;
} else if (product_copy.product_uom[0] == 1 && products_to_update[i].product_qty > 1) { // Unit
product_copy.product_qty_package = 1;
product_copy.package_qty = 1;
product_copy.product_qty = 1;
updatedProducts[i].package_qty -= 1;
updatedProducts[i].product_qty -= 1;
products_to_update[i].package_qty -= 1;
products_to_update[i].product_qty -= 1;
} else { // Not handled, all qty in one order
product_copy.product_qty_package = 0;
product_copy.package_qty = 0;
......@@ -1533,16 +1671,18 @@ function send() {
/* <--- */
// Add product to order's prod list
prod_order_id = updatedProducts[i].id_po;
update_data.orders[prod_order_id]['po'].push(updatedProducts[i]);
prod_order_id = products_to_update[i].id_po;
update_data.orders[prod_order_id]['po'].push(products_to_update[i]);
}
// Only send error report & no barcode list when no given products (ie normal process, end of reception)
if (has_given_products === false) {
/* Create the error report */
// Send changes between items to process and processed items
var error_report_data = {
'group_amount_total' : 0,
'update_type' : updateType,
'updated_products' : updatedProducts,
'updated_products' : products_to_update,
'user_comments': user_comments,
'orders' : []
};
......@@ -1599,6 +1739,7 @@ function send() {
alert('Erreur dans l\'envoi du rapport.');
}
});
}
/* Update orders */
$.ajax({
......@@ -1611,6 +1752,7 @@ function send() {
success: function() {
closeModal();
if (has_given_products === false) {
try {
// If step 1 (counting)
if (reception_status == "False") {
......@@ -1769,6 +1911,7 @@ function send() {
console.error(err);
report_JS_error(err, 'reception');
}
}
},
error: function() {
closeModal();
......
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