This commit is contained in:
Ludovic Stephan 2017-02-12 11:02:54 -02:00
parent 2394a5e5d2
commit 99d04fb75e

View file

@ -989,27 +989,39 @@ $(document).ready(function() {
}
function addExistingPurchase(opeindex, nb) {
type = formset_container.find("#id_form-"+opeindex+"-type").val();
id = formset_container.find("#id_form-"+opeindex+"-article").val();
nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val();
nb_after = parseInt(nb_before) + parseInt(nb);
var type = formset_container.find("#id_form-"+opeindex+"-type").val();
var id = formset_container.find("#id_form-"+opeindex+"-article").val();
var nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val();
var nb_after = parseInt(nb_before) + parseInt(nb);
var amountEuro_after = amountEuroPurchase(id, nb_after);
var amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']);
if (type == 'purchase') {
if (nb_after == 0) {
deleteFromBasket(opeindex);
} else if (nb_after > 0 && nb_after <= 25) {
amountEuro_after = amountEuroPurchase(id, nb_after);
amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']);
var article_html = basket_container.find('[data-opeindex='+opeindex+']');
article_html.find('.amount').text(amountUKF_after).end()
.find('.number').text(nb_after+'/'+article_data[4]).end() ;
if (nb_before > 0) {
var article_html = basket_container.find('[data-opeindex='+opeindex+']');
article_html.find('.amount').text(amountUKF_after).end()
.find('.number').text(nb_after+'/'+article_data[4]).end() ;
if (is_low_stock(id, nb_after))
article_html.find('.lowstock')
.show();
else
article_html.find('.lowstock')
.hide();
} else {
article_html = $(item_basket_default_html);
article_html
.attr('data-opeindex', opeindex)
.find('.number').text('('+nb_after+'/'+article_data[4]+')').end()
.find('.name').text(article_data[0]).end()
.find('.amount').text(amountUKF_after);
basket_container.prepend(article_basket_html);
}
if (is_low_stock(id, nb_after))
article_html.find('.lowstock')
.show();
else
article_html.find('.lowstock')
.hide();
updateExistingFormset(opeindex, nb_after, amountEuro_after);
updateBasketRel();
}
@ -1150,13 +1162,14 @@ $(document).ready(function() {
}
function deleteFromFormset(opeindex) {
formset_container.find('#id_form-'+opeindex+'-DELETE').prop('checked', true);
updateExistingFormset(opeindex, 0, '0.00');
}
function updateExistingFormset(opeindex, nb, amount) {
formset_container
.find('#id_form-'+opeindex+'-amount').val((parseFloat(amount)).toFixed(2)).end()
.find('#id_form-'+opeindex+'-article_nb').val(nb);
.find('#id_form-'+opeindex+'-article_nb').val(nb).end()
.find('#id_form-'+opeindex+'-DELETE').prop('checked', !nb);
}
// -----