Commit 672c5269 by François C.

Merge branch '3438-rec-unmerge-orders' into 'dev_cooperatic'

REC: unmerge orders

See merge request !193
parents 53f28cc4 3a8879bb
Pipeline #2308 passed with stage
in 1 minute 23 seconds
......@@ -15,6 +15,11 @@ input[type="number"] {
margin-bottom: 5px;
}
.group_line_content {
display: flex;
align-items: center;
}
#orders tbody tr {
cursor: pointer;
}
......@@ -44,6 +49,24 @@ input[type="number"] {
color: #e62720;
}
.group_partner_name {
margin: 0 3px;
}
.goto_group_button {
margin-left: 10px;
}
.ungroup_orders_icon {
margin-left: 15px;
color: #d9534f;
cursor: pointer;
}
.ungroup_precisions {
font-style: italic;
}
/* PRODUITS */
.page_body {
height: 100%;
......
......@@ -289,6 +289,71 @@ function group_action() {
}
}
/**
* Remove an orders group.
* Correctly set orders data so ungrouping goes smoothly.
*
* @param {int} group_index index in the groups array
*/
function ungroup(group_index) {
let group = order_groups.groups[group_index];
for (let order_id of group) {
let order_doc_id = 'order_' + order_id;
// Delete group data in each order
dbc.get(order_doc_id).then((doc) => {
if ("updated_products" in doc) {
for (let i = 0; i < doc.updated_products.length; i++) {
delete(doc.updated_products[i].other_orders_data);
}
doc.last_update = {
timestamp: Date.now(),
fingerprint: fingerprint
};
dbc.put(doc).then(() => {})
.catch((err) => {
error = {
msg: 'Erreur dans la creation de la commande dans couchdb',
ctx: 'create_order_doc',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
});
}
})
.catch(function (err) {
error = {
msg: 'Erreur dans la récupération du doc d\'une commande pour suppression d\'un groupe',
ctx: 'ungroup',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
});
}
order_groups.groups.splice(group_index, 1);
dbc.put(order_groups, (err, result) => {
if (!err) {
order_groups._rev = result.rev;
display_orders_table();
display_grouped_orders();
} else {
error = {
msg: 'Erreur dans la mise à jour du doc des groupes pour la suppression',
ctx: 'ungroup',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
}
});
}
/* DISPLAY */
/**
......@@ -296,7 +361,6 @@ function group_action() {
* Remove the grouped orders from the order table to prevent grouping in multiple groups.
*/
function display_grouped_orders() {
if (table_orders !== null) {
var display_something = false;
......@@ -326,33 +390,57 @@ function display_grouped_orders() {
// Display group
display_something = true;
document.getElementById("container_groups").hidden = false;
let group_row = `<li class="group_line"> Commandes de `;
let group_row = `<li class="group_line" group_index="${group_index}"><span class="group_line_content"> Commandes de `;
for (let i in group_orders) {
if (i == group_orders.length-1) { // last element of list
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + " : ";
} else {
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + ", ";
group_row += `<b class="group_partner_name">${group_orders[i].partner}</b> du ${group_orders[i].date_order}`;
if (i != group_orders.length-1) { // for other elements than last of list
group_row += ", ";
}
}
if (group_orders[0].reception_status == 'False') {
group_row += "<button class='btn--primary' onClick='group_goto("
+ group_index
+ ")'>Compter les produits</button>";
group_row += `
<button class='btn--primary goto_group_button' onClick='group_goto(${group_index})'>
Compter les produits
</button>`;
} else {
group_row += "<button class='btn--success' onClick='group_goto("
+ group_index
+ ")'>Mettre à jour les prix</button>";
group_row += `
<button class='btn--success goto_group_button' onClick='group_goto(${group_index})'>
Mettre à jour les prix
</button>`;
}
group_row += "</li>";
group_row += `<i class="fas fa-times fa-lg ungroup_orders_icon"></i>`;
group_row += "</span></li>";
groups_display_content += group_row;
}
}
if (display_something === true) {
$('#container_groups').show();
$('#groups_items').append(groups_display_content);
setTimeout(() => {
$(".ungroup_orders_icon").off("click");
$(".ungroup_orders_icon").on("click", function() {
let modal_template = $("#modal_delete_group");
let group_to_delete_index = $(this).closest(".group_line")
.attr("group_index");
openModal(
modal_template.html(),
() => {
ungroup(group_to_delete_index);
},
"Confirmer"
);
});
}, 100);
} else {
$('#container_groups').hide();
}
}
}
......@@ -593,9 +681,8 @@ $(document).ready(function() {
order_groups = doc;
})
.catch(function (err) {
console.log(err);
if (err.status === 404) {
// Create if doesn't exist
// Create if doesn't exist
dbc.put(order_groups, (err, result) => {
if (!err) {
order_groups._rev = result.rev;
......@@ -604,6 +691,14 @@ $(document).ready(function() {
console.log(err);
}
});
} else {
error = {
msg: 'Erreur dans la récupération des groupes dans couchdb',
ctx: 'document_init',
details: err
};
report_JS_error(error, 'reception');
console.log(error);
}
});
......
......@@ -631,14 +631,14 @@ function initLists() {
title:"Prix unit",
className:"dt-body-center",
visible: (reception_status == "qty_valid"),
width: "5%",
width: "5%"
},
{
title:"Editer",
defaultContent: "<a class='btn' id='processed_line_edit' href='#'><i class='far fa-edit'></i></a>",
className:"dt-body-center",
orderable: false,
width: "5%",
width: "5%"
},
{
title:"Autres",
......@@ -666,12 +666,10 @@ function initLists() {
// For grouped orders, order first by number of order, then by product id
if (is_grouped_order()) {
table_to_process_ordering.push(
[
1,
"asc"
]
)
table_to_process_ordering.push([
1,
"asc"
]);
}
// Init table for to_process content
......@@ -944,7 +942,7 @@ function initLists() {
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.")
alert("Il y a déjà un produit dans la zone d'édition. Terminez d'abord d'éditer ce produit.");
}
});
......@@ -975,7 +973,7 @@ function initLists() {
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.")
alert("Il y a déjà un produit dans la zone d'édition. Terminez d'abord d'éditer ce produit.");
}
});
}
......@@ -1269,16 +1267,16 @@ function editProductInfo (productToEdit, value = null, batch = false) {
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)
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;
......@@ -1582,7 +1580,7 @@ function data_validation() {
/**
* 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.
......@@ -1686,12 +1684,12 @@ function send(given_products = []) {
'user_comments': user_comments,
'orders' : []
};
for (let i in orders) {
error_report_data.group_amount_total += orders[i].amount_total;
error_report_data.orders.push(orders[i]);
}
//Create list of articl with no barcode
no_barcode_list = [];
for (var i = 0; i < list_processed.length; i++) {
......@@ -1702,13 +1700,13 @@ function send(given_products = []) {
]);
}
}
data_send_no_barcode={
"order" : orders[order_data['id_po']],
"no_barcode_list" : no_barcode_list
};
// Send of articl with no barcode to mail send
if (no_barcode_list.length > 0) {
$.ajax({
......@@ -1724,7 +1722,7 @@ function send(given_products = []) {
}
});
}
// Send request for error report
$.ajax({
type: "POST",
......@@ -1758,7 +1756,7 @@ function send(given_products = []) {
if (reception_status == "False") {
/* Open pop-up with procedure explanation */
var barcodes_to_print = false;
// Select products with local barcode and without barcode, when qty > 0
for (var i = 0; i < list_processed.length; i++) {
if (list_processed[i].product_qty != 0) {
......@@ -1767,16 +1765,16 @@ function send(given_products = []) {
// Products with barcode to print (local barcode)
document.getElementById("barcodesToPrint").hidden = false;
document.getElementById("nothingToDo").hidden = true;
barcodes_to_print = true;
} /* else if (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "") {
// Products with no barcode
var node = document.createElement('li');
let textNode = document.createTextNode(list_processed[i]["product_id"][1]);
node.appendChild(textNode);
document.getElementById('barcodesEmpty_list').appendChild(node);
if (document.getElementById("barcodesEmpty").hidden) {
document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true;
......@@ -1784,46 +1782,46 @@ function send(given_products = []) {
}*/
}
}
for (let i = 0; i < no_barcode_list.length; i++) {
var node = document.createElement('li');
let textNode = document.createTextNode(no_barcode_list[i]);
node.appendChild(textNode);
document.getElementById('barcodesEmpty_list').appendChild(node);
if (document.getElementById("barcodesEmpty").hidden) {
document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true;
}
}
// Set order(s) name in popup DOM
if (is_grouped_order() === false) { // Single order
document.getElementById("order_ref").innerHTML = orders[Object.keys(orders)[0]].name;
} else { // group
document.getElementById("success_order_name_container").hidden = true;
document.getElementById("success_orders_name_container").hidden = false;
for (order_id in orders) {
var p_node = document.createElement('p');
var span_node = document.createElement('span');
span_node.className = 'order_ref_reminder';
let textNode = document.createTextNode(orders[order_id].name);
span_node.appendChild(textNode);
textNode = document.createTextNode(orders[order_id].partner
+ ' du ' + orders[order_id].date_order + ' : ');
p_node.appendChild(textNode);
p_node.appendChild(span_node);
document.getElementById("orders_ref").appendChild(p_node);
}
}
openModal(
$('#modal_qtiesValidated').html(),
back,
......@@ -1831,7 +1829,7 @@ function send(given_products = []) {
true,
false
);
/* Not last step: update distant data */
for (let order_id in orders) {
// Save current step updated data
......@@ -1841,18 +1839,18 @@ function send(given_products = []) {
user_comments: user_comments
};
orders[order_id].reception_status = updateType;
// Unlock order
orders[order_id].last_update = {
timestamp: null,
fingerprint: null
};
// Delete temp data
delete orders[order_id].valid_products;
delete orders[order_id].updated_products;
}
dbc.bulkDocs(Object.values(orders)).catch((err) => {
console.log(err);
});
......@@ -1861,7 +1859,7 @@ function send(given_products = []) {
if (updatedProducts.length > 0) {
document.getElementById("etiquettesToPrint").hidden = false;
}
openModal(
$('#templates #modal_pricesValidated').html(),
back,
......@@ -1869,40 +1867,40 @@ function send(given_products = []) {
true,
false
);
/* Last step: Clear distant data */
// Delete orders doc
for (let order_id in orders) {
orders[order_id]._deleted = true;
}
// Remove orders group
dbc.get("grouped_orders").then((doc) => {
let couchdb_update_data = Object.values(orders);
// We're in a group, remove it & update groups doc
if (is_grouped_order()) {
let groups_doc = doc;
let first_order_id = parseInt(Object.keys(orders)[0]);
for (let i in groups_doc.groups) {
if (groups_doc.groups[i].includes(first_order_id)) {
groups_doc.groups.splice(i, 1);
break;
}
}
couchdb_update_data.push(groups_doc);
}
return dbc.bulkDocs(couchdb_update_data);
})
.catch(function (err) {
console.log(err);
});
}
// Back if modal closed
$('#modal_closebtn_top').on('click', back);
$('#modal_closebtn_bottom').on('click', back);
......@@ -2214,10 +2212,10 @@ function openErrorReport() {
* If extists, destroys instance and recreate it.
* Filter autocomplete data by removing products already selected.
*/
function set_products_autocomplete() {
function set_products_autocomplete() {
// Filter autocomplete products on products already selected
let autocomplete_products = suppliers_products.filter(p => products_to_add.findIndex(pta => pta.name === p.name) === -1);
try {
$("#modal .search_product_input").autocomplete("destroy");
} catch (error) {
......@@ -2291,19 +2289,19 @@ function set_add_products_modal() {
);
} else {
let add_products_modal = $("#modal_add_products");
openModal(
add_products_modal.html(),
add_products_action,
'Ajouter les produits',
false
);
products_to_add = []; // Reset on modal opening
set_products_autocomplete();
}
}
/**
* Init the page according to order(s) data (texts, colors, events...)
......
......@@ -59,7 +59,21 @@
</p><br/>
<p>Voulez-vous quand même y accéder ?</p>
<hr/>
</div>
</div>
<div id="modal_delete_group">
<h3>Attention !</h3>
<p>Vous vous apprêtez à défusionner un groupe de commandes.</p>
<p>
Les données de réception des différentes commandes seront conservées.<br/>
<span class="ungroup_precisions">
Attention aux produits se trouvant dans plusieurs commandes !
Bien vérifier les données dans chaque commande.
</span>
</p>
<p>
Êtez-vous sûr.e ?<br/>
</p>
</div>
</div>
<br/>
......
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