Commit 10127a48 by Damien Moulard

delete envelop button

parent 7a0149bc
Pipeline #1335 passed with stage
in 1 minute 25 seconds
...@@ -91,7 +91,7 @@ class CagetteEnvelops(models.Model): ...@@ -91,7 +91,7 @@ class CagetteEnvelops(models.Model):
if not ('error' in res): if not ('error' in res):
try: try:
if int(float(data['amount']) * 100) == int(float(invoice['residual_signed']) * 100): if int(float(data['amount']) * 100) == int(float(invoice['residual_signed']) * 100):
# This payment is what it was left to pay, so change invoice state # This payment is what was left to pay, so change invoice state
self.o_api.update('account.invoice', [invoice['id']], {'state': 'paid'}) self.o_api.update('account.invoice', [invoice['id']], {'state': 'paid'})
except Exception as e: except Exception as e:
res['error'] = repr(e) res['error'] = repr(e)
......
...@@ -16,6 +16,10 @@ function toggle_success_alert() { ...@@ -16,6 +16,10 @@ function toggle_success_alert() {
$('#envelop_cashing_success').toggle(250); $('#envelop_cashing_success').toggle(250);
} }
function toggle_deleted_alert() {
$('#envelop_deletion_success').toggle(250);
}
// Set an envelop content on the document // Set an envelop content on the document
function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_index) { function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_index) {
var envelops_section = $('#' + envelop.type + '_envelops'); var envelops_section = $('#' + envelop.type + '_envelops');
...@@ -39,7 +43,7 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -39,7 +43,7 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
} }
new_html += '</div>' new_html += '</div>'
+ '<div class="panel"><ol id="' + envelop_content_id + '"></ol></div>' + '<div class="panel panel_' + envelop_content_id + '"><ol id="' + envelop_content_id + '"></ol></div>'
+ '</div>'; + '</div>';
$(new_html).appendTo(envelops_section); $(new_html).appendTo(envelops_section);
...@@ -58,6 +62,9 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde ...@@ -58,6 +62,9 @@ function set_envelop_dom(envelop, envelop_name, envelop_content_id, envelop_inde
li_node.appendChild(textnode); // Append the text to <li> li_node.appendChild(textnode); // Append the text to <li>
document.getElementById(envelop_content_id).appendChild(li_node); document.getElementById(envelop_content_id).appendChild(li_node);
} }
let envelop_panel = $(`.panel_${envelop_content_id}`);
envelop_panel.append('<button class="btn--danger delete_envelop_button item-fluid" onClick="openModal(\'<h3>Supprimer enveloppe ?</h3>\', function() {delete_envelop(\'' + envelop.type + '\', ' + envelop_index + ');}, \'Supprimer\')">Supprimer l\'enveloppe</button>');
} }
// Set the envelops data according to their type // Set the envelops data according to their type
...@@ -118,7 +125,33 @@ function set_envelops(envelops) { ...@@ -118,7 +125,33 @@ function set_envelops(envelops) {
} }
} }
function delete_envelop(type, index) {
if (is_time_to('delete_envelop', 1000)) {
openModal();
var envelop = null;
if (type == "cash") {
envelop = cash_envelops[index];
} else {
envelop = ch_envelops[index];
}
envelop._deleted = true;
dbc.put(envelop, function callback(err, result) {
if (!err && result !== undefined) {
toggle_deleted_alert();
get_envelops();
} else {
alert("Erreur lors de la suppression de l'enveloppe... Essaye de recharger la page et réessaye.");
console.log(err);
}
});
}
}
function archive_envelop(type, index) { function archive_envelop(type, index) {
if (is_time_to('archive_envelop', 1000)) {
$('#envelop_cashing_error').hide(); $('#envelop_cashing_error').hide();
$('#envelop_cashing_success').hide(); $('#envelop_cashing_success').hide();
// Loading on // Loading on
...@@ -179,6 +212,7 @@ function archive_envelop(type, index) { ...@@ -179,6 +212,7 @@ function archive_envelop(type, index) {
alert('Erreur serveur. Merci de ne pas ré-encaisser l\'enveloppe qui a causé l\'erreur.'); alert('Erreur serveur. Merci de ne pas ré-encaisser l\'enveloppe qui a causé l\'erreur.');
} }
}); });
}
} }
// Get all the envelops from couch db // Get all the envelops from couch db
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
<div style="width: 90%" class="fl txtleft">Enveloppe encaissée !</div> <div style="width: 90%" class="fl txtleft">Enveloppe encaissée !</div>
<div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div> <div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div>
</div> </div>
<div id="envelop_deletion_success" class="alert--success clearfix custom_alert" onClick="toggle_deleted_alert()">
<div style="width: 90%" class="fl txtleft">Enveloppe supprimée !</div>
<div style="width: 10%" class="fr txtright"><i class="fas fa-times"></i></div>
</div>
<section class="grid-2 has-gutter"> <section class="grid-2 has-gutter">
<section id="cash"> <section id="cash">
......
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