Commit 45b3fc2a by Damien Moulard

REC: unmerge orders

parent 53f28cc4
Pipeline #2304 passed with stage
in 1 minute 25 seconds
...@@ -15,6 +15,11 @@ input[type="number"] { ...@@ -15,6 +15,11 @@ input[type="number"] {
margin-bottom: 5px; margin-bottom: 5px;
} }
.group_line_content {
display: flex;
align-items: center;
}
#orders tbody tr { #orders tbody tr {
cursor: pointer; cursor: pointer;
} }
...@@ -44,6 +49,24 @@ input[type="number"] { ...@@ -44,6 +49,24 @@ input[type="number"] {
color: #e62720; 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 */ /* PRODUITS */
.page_body { .page_body {
height: 100%; height: 100%;
......
...@@ -289,6 +289,59 @@ function group_action() { ...@@ -289,6 +289,59 @@ 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) {
console.log(err);
});
}
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 {
console.log(err);
}
});
}
/* DISPLAY */ /* DISPLAY */
/** /**
...@@ -296,7 +349,6 @@ function group_action() { ...@@ -296,7 +349,6 @@ function group_action() {
* Remove the grouped orders from the order table to prevent grouping in multiple groups. * Remove the grouped orders from the order table to prevent grouping in multiple groups.
*/ */
function display_grouped_orders() { function display_grouped_orders() {
if (table_orders !== null) { if (table_orders !== null) {
var display_something = false; var display_something = false;
...@@ -326,33 +378,57 @@ function display_grouped_orders() { ...@@ -326,33 +378,57 @@ function display_grouped_orders() {
// Display group // Display group
display_something = true; display_something = true;
document.getElementById("container_groups").hidden = false; 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) { for (let i in group_orders) {
if (i == group_orders.length-1) { // last element of list group_row += `<b class="group_partner_name">${group_orders[i].partner}</b> du ${group_orders[i].date_order}`;
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + " : "; if (i != group_orders.length-1) { // for other elements than last of list
} else { group_row += ", ";
group_row += "<b>" + group_orders[i].partner + "</b> du " + group_orders[i].date_order + ", ";
} }
} }
if (group_orders[0].reception_status == 'False') { if (group_orders[0].reception_status == 'False') {
group_row += "<button class='btn--primary' onClick='group_goto(" group_row += `
+ group_index <button class='btn--primary goto_group_button' onClick='group_goto(${group_index})'>
+ ")'>Compter les produits</button>"; Compter les produits
</button>`;
} else { } else {
group_row += "<button class='btn--success' onClick='group_goto(" group_row += `
+ group_index <button class='btn--success goto_group_button' onClick='group_goto(${group_index})'>
+ ")'>Mettre à jour les prix</button>"; 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; groups_display_content += group_row;
} }
} }
if (display_something === true) { if (display_something === true) {
$('#container_groups').show(); $('#container_groups').show();
$('#groups_items').append(groups_display_content); $('#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 +669,8 @@ $(document).ready(function() { ...@@ -593,9 +669,8 @@ $(document).ready(function() {
order_groups = doc; order_groups = doc;
}) })
.catch(function (err) { .catch(function (err) {
console.log(err);
if (err.status === 404) { if (err.status === 404) {
// Create if doesn't exist // Create if doesn't exist
dbc.put(order_groups, (err, result) => { dbc.put(order_groups, (err, result) => {
if (!err) { if (!err) {
order_groups._rev = result.rev; order_groups._rev = result.rev;
...@@ -604,6 +679,8 @@ $(document).ready(function() { ...@@ -604,6 +679,8 @@ $(document).ready(function() {
console.log(err); console.log(err);
} }
}); });
} else {
console.log(err);
} }
}); });
......
...@@ -631,14 +631,14 @@ function initLists() { ...@@ -631,14 +631,14 @@ function initLists() {
title:"Prix unit", title:"Prix unit",
className:"dt-body-center", className:"dt-body-center",
visible: (reception_status == "qty_valid"), visible: (reception_status == "qty_valid"),
width: "5%", width: "5%"
}, },
{ {
title:"Editer", title:"Editer",
defaultContent: "<a class='btn' id='processed_line_edit' href='#'><i class='far fa-edit'></i></a>", defaultContent: "<a class='btn' id='processed_line_edit' href='#'><i class='far fa-edit'></i></a>",
className:"dt-body-center", className:"dt-body-center",
orderable: false, orderable: false,
width: "5%", width: "5%"
}, },
{ {
title:"Autres", title:"Autres",
...@@ -666,12 +666,10 @@ function initLists() { ...@@ -666,12 +666,10 @@ function initLists() {
// For grouped orders, order first by number of order, then by product id // For grouped orders, order first by number of order, then by product id
if (is_grouped_order()) { if (is_grouped_order()) {
table_to_process_ordering.push( table_to_process_ordering.push([
[ 1,
1, "asc"
"asc" ]);
]
)
} }
// Init table for to_process content // Init table for to_process content
...@@ -944,7 +942,7 @@ function initLists() { ...@@ -944,7 +942,7 @@ function initLists() {
alert('Mauvais mot de passe !'); alert('Mauvais mot de passe !');
} }
} else { } 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() { ...@@ -975,7 +973,7 @@ function initLists() {
alert('Mauvais mot de passe !'); alert('Mauvais mot de passe !');
} }
} else { } 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) { ...@@ -1269,16 +1267,16 @@ function editProductInfo (productToEdit, value = null, batch = false) {
if (previous_step_index === -1) { if (previous_step_index === -1) {
// Product qty hasn't been updated yet: add to first step data // Product qty hasn't been updated yet: add to first step data
productToEdit.old_qty = productToEdit.product_qty; productToEdit.old_qty = productToEdit.product_qty;
productToEdit.product_qty = newValue; productToEdit.product_qty = newValue;
productToEdit.product_qty_package = 1; productToEdit.product_qty_package = 1;
productToEdit.package_qty = productToEdit.product_qty; 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 { } else {
productToEdit.product_qty = newValue; productToEdit.product_qty = newValue;
productToEdit.package_qty = productToEdit.product_qty; productToEdit.package_qty = productToEdit.product_qty;
// Product qty has been updated before, update first step data // 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].product_qty = newValue;
orders[productToEdit.id_po]["previous_steps_data"]["False"]["updated_products"][previous_step_index].package_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() { ...@@ -1582,7 +1580,7 @@ function data_validation() {
/** /**
* Send the request to update order(s) data * Send the request to update order(s) data
* *
* @param {Array} given_products If set, only update these products. * @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. * 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. * Else, we're in the middle of a reception, so we'll skip some parts.
...@@ -1686,12 +1684,12 @@ function send(given_products = []) { ...@@ -1686,12 +1684,12 @@ function send(given_products = []) {
'user_comments': user_comments, 'user_comments': user_comments,
'orders' : [] 'orders' : []
}; };
for (let i in orders) { for (let i in orders) {
error_report_data.group_amount_total += orders[i].amount_total; error_report_data.group_amount_total += orders[i].amount_total;
error_report_data.orders.push(orders[i]); error_report_data.orders.push(orders[i]);
} }
//Create list of articl with no barcode //Create list of articl with no barcode
no_barcode_list = []; no_barcode_list = [];
for (var i = 0; i < list_processed.length; i++) { for (var i = 0; i < list_processed.length; i++) {
...@@ -1702,13 +1700,13 @@ function send(given_products = []) { ...@@ -1702,13 +1700,13 @@ function send(given_products = []) {
]); ]);
} }
} }
data_send_no_barcode={ data_send_no_barcode={
"order" : orders[order_data['id_po']], "order" : orders[order_data['id_po']],
"no_barcode_list" : no_barcode_list "no_barcode_list" : no_barcode_list
}; };
// Send of articl with no barcode to mail send // Send of articl with no barcode to mail send
if (no_barcode_list.length > 0) { if (no_barcode_list.length > 0) {
$.ajax({ $.ajax({
...@@ -1724,7 +1722,7 @@ function send(given_products = []) { ...@@ -1724,7 +1722,7 @@ function send(given_products = []) {
} }
}); });
} }
// Send request for error report // Send request for error report
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -1758,7 +1756,7 @@ function send(given_products = []) { ...@@ -1758,7 +1756,7 @@ function send(given_products = []) {
if (reception_status == "False") { if (reception_status == "False") {
/* Open pop-up with procedure explanation */ /* Open pop-up with procedure explanation */
var barcodes_to_print = false; var barcodes_to_print = false;
// Select products with local barcode and without barcode, when qty > 0 // Select products with local barcode and without barcode, when qty > 0
for (var i = 0; i < list_processed.length; i++) { for (var i = 0; i < list_processed.length; i++) {
if (list_processed[i].product_qty != 0) { if (list_processed[i].product_qty != 0) {
...@@ -1767,16 +1765,16 @@ function send(given_products = []) { ...@@ -1767,16 +1765,16 @@ function send(given_products = []) {
// Products with barcode to print (local barcode) // Products with barcode to print (local barcode)
document.getElementById("barcodesToPrint").hidden = false; document.getElementById("barcodesToPrint").hidden = false;
document.getElementById("nothingToDo").hidden = true; document.getElementById("nothingToDo").hidden = true;
barcodes_to_print = true; barcodes_to_print = true;
} /* else if (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "") { } /* else if (list_processed[i].barcode == false || list_processed[i].barcode == null || list_processed[i].barcode == "") {
// Products with no barcode // Products with no barcode
var node = document.createElement('li'); var node = document.createElement('li');
let textNode = document.createTextNode(list_processed[i]["product_id"][1]); let textNode = document.createTextNode(list_processed[i]["product_id"][1]);
node.appendChild(textNode); node.appendChild(textNode);
document.getElementById('barcodesEmpty_list').appendChild(node); document.getElementById('barcodesEmpty_list').appendChild(node);
if (document.getElementById("barcodesEmpty").hidden) { if (document.getElementById("barcodesEmpty").hidden) {
document.getElementById("barcodesEmpty").hidden = false; document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true; document.getElementById("nothingToDo").hidden = true;
...@@ -1784,46 +1782,46 @@ function send(given_products = []) { ...@@ -1784,46 +1782,46 @@ function send(given_products = []) {
}*/ }*/
} }
} }
for (let i = 0; i < no_barcode_list.length; i++) { for (let i = 0; i < no_barcode_list.length; i++) {
var node = document.createElement('li'); var node = document.createElement('li');
let textNode = document.createTextNode(no_barcode_list[i]); let textNode = document.createTextNode(no_barcode_list[i]);
node.appendChild(textNode); node.appendChild(textNode);
document.getElementById('barcodesEmpty_list').appendChild(node); document.getElementById('barcodesEmpty_list').appendChild(node);
if (document.getElementById("barcodesEmpty").hidden) { if (document.getElementById("barcodesEmpty").hidden) {
document.getElementById("barcodesEmpty").hidden = false; document.getElementById("barcodesEmpty").hidden = false;
document.getElementById("nothingToDo").hidden = true; document.getElementById("nothingToDo").hidden = true;
} }
} }
// Set order(s) name in popup DOM // Set order(s) name in popup DOM
if (is_grouped_order() === false) { // Single order if (is_grouped_order() === false) { // Single order
document.getElementById("order_ref").innerHTML = orders[Object.keys(orders)[0]].name; document.getElementById("order_ref").innerHTML = orders[Object.keys(orders)[0]].name;
} else { // group } else { // group
document.getElementById("success_order_name_container").hidden = true; document.getElementById("success_order_name_container").hidden = true;
document.getElementById("success_orders_name_container").hidden = false; document.getElementById("success_orders_name_container").hidden = false;
for (order_id in orders) { for (order_id in orders) {
var p_node = document.createElement('p'); var p_node = document.createElement('p');
var span_node = document.createElement('span'); var span_node = document.createElement('span');
span_node.className = 'order_ref_reminder'; span_node.className = 'order_ref_reminder';
let textNode = document.createTextNode(orders[order_id].name); let textNode = document.createTextNode(orders[order_id].name);
span_node.appendChild(textNode); span_node.appendChild(textNode);
textNode = document.createTextNode(orders[order_id].partner textNode = document.createTextNode(orders[order_id].partner
+ ' du ' + orders[order_id].date_order + ' : '); + ' du ' + orders[order_id].date_order + ' : ');
p_node.appendChild(textNode); p_node.appendChild(textNode);
p_node.appendChild(span_node); p_node.appendChild(span_node);
document.getElementById("orders_ref").appendChild(p_node); document.getElementById("orders_ref").appendChild(p_node);
} }
} }
openModal( openModal(
$('#modal_qtiesValidated').html(), $('#modal_qtiesValidated').html(),
back, back,
...@@ -1831,7 +1829,7 @@ function send(given_products = []) { ...@@ -1831,7 +1829,7 @@ function send(given_products = []) {
true, true,
false false
); );
/* Not last step: update distant data */ /* Not last step: update distant data */
for (let order_id in orders) { for (let order_id in orders) {
// Save current step updated data // Save current step updated data
...@@ -1841,18 +1839,18 @@ function send(given_products = []) { ...@@ -1841,18 +1839,18 @@ function send(given_products = []) {
user_comments: user_comments user_comments: user_comments
}; };
orders[order_id].reception_status = updateType; orders[order_id].reception_status = updateType;
// Unlock order // Unlock order
orders[order_id].last_update = { orders[order_id].last_update = {
timestamp: null, timestamp: null,
fingerprint: null fingerprint: null
}; };
// Delete temp data // Delete temp data
delete orders[order_id].valid_products; delete orders[order_id].valid_products;
delete orders[order_id].updated_products; delete orders[order_id].updated_products;
} }
dbc.bulkDocs(Object.values(orders)).catch((err) => { dbc.bulkDocs(Object.values(orders)).catch((err) => {
console.log(err); console.log(err);
}); });
...@@ -1861,7 +1859,7 @@ function send(given_products = []) { ...@@ -1861,7 +1859,7 @@ function send(given_products = []) {
if (updatedProducts.length > 0) { if (updatedProducts.length > 0) {
document.getElementById("etiquettesToPrint").hidden = false; document.getElementById("etiquettesToPrint").hidden = false;
} }
openModal( openModal(
$('#templates #modal_pricesValidated').html(), $('#templates #modal_pricesValidated').html(),
back, back,
...@@ -1869,40 +1867,40 @@ function send(given_products = []) { ...@@ -1869,40 +1867,40 @@ function send(given_products = []) {
true, true,
false false
); );
/* Last step: Clear distant data */ /* Last step: Clear distant data */
// Delete orders doc // Delete orders doc
for (let order_id in orders) { for (let order_id in orders) {
orders[order_id]._deleted = true; orders[order_id]._deleted = true;
} }
// Remove orders group // Remove orders group
dbc.get("grouped_orders").then((doc) => { dbc.get("grouped_orders").then((doc) => {
let couchdb_update_data = Object.values(orders); let couchdb_update_data = Object.values(orders);
// We're in a group, remove it & update groups doc // We're in a group, remove it & update groups doc
if (is_grouped_order()) { if (is_grouped_order()) {
let groups_doc = doc; let groups_doc = doc;
let first_order_id = parseInt(Object.keys(orders)[0]); let first_order_id = parseInt(Object.keys(orders)[0]);
for (let i in groups_doc.groups) { for (let i in groups_doc.groups) {
if (groups_doc.groups[i].includes(first_order_id)) { if (groups_doc.groups[i].includes(first_order_id)) {
groups_doc.groups.splice(i, 1); groups_doc.groups.splice(i, 1);
break; break;
} }
} }
couchdb_update_data.push(groups_doc); couchdb_update_data.push(groups_doc);
} }
return dbc.bulkDocs(couchdb_update_data); return dbc.bulkDocs(couchdb_update_data);
}) })
.catch(function (err) { .catch(function (err) {
console.log(err); console.log(err);
}); });
} }
// Back if modal closed // Back if modal closed
$('#modal_closebtn_top').on('click', back); $('#modal_closebtn_top').on('click', back);
$('#modal_closebtn_bottom').on('click', back); $('#modal_closebtn_bottom').on('click', back);
...@@ -2214,10 +2212,10 @@ function openErrorReport() { ...@@ -2214,10 +2212,10 @@ function openErrorReport() {
* If extists, destroys instance and recreate it. * If extists, destroys instance and recreate it.
* Filter autocomplete data by removing products already selected. * Filter autocomplete data by removing products already selected.
*/ */
function set_products_autocomplete() { function set_products_autocomplete() {
// Filter autocomplete products on products already selected // Filter autocomplete products on products already selected
let autocomplete_products = suppliers_products.filter(p => products_to_add.findIndex(pta => pta.name === p.name) === -1); let autocomplete_products = suppliers_products.filter(p => products_to_add.findIndex(pta => pta.name === p.name) === -1);
try { try {
$("#modal .search_product_input").autocomplete("destroy"); $("#modal .search_product_input").autocomplete("destroy");
} catch (error) { } catch (error) {
...@@ -2291,19 +2289,19 @@ function set_add_products_modal() { ...@@ -2291,19 +2289,19 @@ function set_add_products_modal() {
); );
} else { } else {
let add_products_modal = $("#modal_add_products"); let add_products_modal = $("#modal_add_products");
openModal( openModal(
add_products_modal.html(), add_products_modal.html(),
add_products_action, add_products_action,
'Ajouter les produits', 'Ajouter les produits',
false false
); );
products_to_add = []; // Reset on modal opening products_to_add = []; // Reset on modal opening
set_products_autocomplete(); set_products_autocomplete();
} }
} }
/** /**
* Init the page according to order(s) data (texts, colors, events...) * Init the page according to order(s) data (texts, colors, events...)
......
...@@ -59,7 +59,19 @@ ...@@ -59,7 +59,19 @@
</p><br/> </p><br/>
<p>Voulez-vous quand même y accéder ?</p> <p>Voulez-vous quand même y accéder ?</p>
<hr/> <hr/>
</div> </div>
<div id="modal_delete_group">
<h3>Attention !</h3>
<p>Vous vous apprêtez à défusionner un groupe de commandes.</p>
<p>
Il est conseillé de conserver les groupes jusqu'au bout de la réception autant que possible,
par soucis de cohérence du rapport de réception.
</p>
<p>
Si vous souhaitez tout de même défusionner les commandes, cliquez sur Confirmer.<br/>
<span class="ungroup_precisions">Les données de réception des différentes commandes seront concervées.</span>
</p>
</div>
</div> </div>
<br/> <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