forked from DGNum/gestioCOF
Fin panier ?
- Ajout des infos panier en fonction du trigramme (LIQ ou compte) - Mise à jour des infos panier si le compte sélectionné change - Correction sur calcul d'un montant en UKF
This commit is contained in:
parent
09499886a8
commit
b8ae482a60
1 changed files with 51 additions and 12 deletions
|
@ -136,8 +136,8 @@ $(document).ready(function() {
|
|||
|
||||
function amountToUKF(amount, is_cof=false) {
|
||||
if (is_cof)
|
||||
return Math.round(amount * (1+subvention_cof/100) * 100) / 10;
|
||||
return Math.round(amount * 100) / 10;
|
||||
return Math.round(amount * (1+subvention_cof/100) * 10);
|
||||
return Math.round(amount * 10);
|
||||
}
|
||||
|
||||
// -----
|
||||
|
@ -201,6 +201,7 @@ $(document).ready(function() {
|
|||
// Store data
|
||||
function storeAccountData(data) {
|
||||
account_data = $.extend({}, account_data_default, data);
|
||||
account_data['balance'] = parseFloat(account_data['balance']);
|
||||
$('#id_on_acc').val(account_data['pk']);
|
||||
displayAccountData();
|
||||
}
|
||||
|
@ -215,7 +216,9 @@ $(document).ready(function() {
|
|||
})
|
||||
.done(function(data) {
|
||||
storeAccountData(data);
|
||||
articleSelect.focus();
|
||||
articleSelect.focus();
|
||||
updateBasketAmount();
|
||||
updateBasketRel();
|
||||
})
|
||||
.fail(function() { resetAccountData() });
|
||||
}
|
||||
|
@ -548,15 +551,18 @@ $(document).ready(function() {
|
|||
var basket_container = $('#basket table');
|
||||
var arrowKeys = /^(37|38|39|40)$/;
|
||||
|
||||
function addPurchase(id, nb) {
|
||||
function amountEuroPurchase(id,nb) {
|
||||
var i = 0;
|
||||
while (i<articlesList.length && id != articlesList[i][1]) i++;
|
||||
article_data = articlesList[i];
|
||||
var reduc_divisor = 1;
|
||||
if (account_data['is_cof'])
|
||||
reduc_divisor = 1 + subvention_cof / 100;
|
||||
console.log(reduc_divisor);
|
||||
var amount_euro = - article_data[3] * nb / reduc_divisor;
|
||||
return - article_data[3] * nb / reduc_divisor;
|
||||
}
|
||||
|
||||
function addPurchase(id, nb) {
|
||||
var amount_euro = amountEuroPurchase(id, nb);
|
||||
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
||||
article_basket_html = $(item_basket_default_html);
|
||||
article_basket_html
|
||||
|
@ -604,6 +610,10 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
function isBasketEmpty() {
|
||||
return !basket_container.find('[data-opeindex]').length;
|
||||
}
|
||||
|
||||
function getAmountBasket() {
|
||||
var total = 0;
|
||||
formset_container.find('[data-opeindex]').each(function () {
|
||||
|
@ -614,21 +624,50 @@ $(document).ready(function() {
|
|||
return total;
|
||||
}
|
||||
|
||||
function updateBasketAmount() {
|
||||
formset_container.find('[data-opeindex]').each(function () {
|
||||
var opeindex = $(this).attr('data-opeindex');
|
||||
var deleted = $(this).find('#id_form-'+opeindex+'-DELETE').prop('checked');
|
||||
var type = $(this).find('#id_form-'+opeindex+'-type').val();
|
||||
var article_id = $(this).find('#id_form-'+opeindex+'-article').val();
|
||||
var article_nb = $(this).find('#id_form-'+opeindex+'-article_nb').val();
|
||||
var amount = $(this).find('#id_form-'+opeindex+'-amount');
|
||||
if (!deleted && type == "purchase")
|
||||
amount.val(amountEuroPurchase(article_id, article_nb));
|
||||
basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_data['is_cof']));
|
||||
});
|
||||
}
|
||||
|
||||
var basketrel_container = $('#basket_rel');
|
||||
|
||||
/*
|
||||
function updateBasketRel() {
|
||||
if (account_data['trigramme'] == 'LIQ') {
|
||||
var basketrel_html = '';
|
||||
} else {
|
||||
var basketrel_html = 'Total: '+amountToUKF(getAmountBasket(), account_data['id_cof']);
|
||||
var basketrel_html = '';
|
||||
if (account_data['trigramme'] == 'LIQ' && !isBasketEmpty()) {
|
||||
var amount = - getAmountBasket();
|
||||
basketrel_html += '<div>Total: '+amount.toFixed(2)+' €</div>';
|
||||
if (amount < 5)
|
||||
basketrel_html += '<div>Sur 5€: '+ (5-amount).toFixed(2) +' €</div>';
|
||||
if (amount < 10)
|
||||
basketrel_html += '<div>Sur 10€: '+ (10-amount).toFixed(2) +' €</div>';
|
||||
if (amount < 20)
|
||||
basketrel_html += '<div>Sur 20€: '+ (20-amount).toFixed(2) +' €</div>';
|
||||
} else if (account_data['trigramme'] != '' && !isBasketEmpty()) {
|
||||
var amount = getAmountBasket();
|
||||
var amountUKF = amountToUKF(amount, account_data['is_cof']);
|
||||
var newBalance = account_data['balance'] + amount;
|
||||
var newBalanceUKF = amountToUKF(newBalance, account_data['is_cof']);
|
||||
basketrel_html += '<div>Total: '+amountUKF+'</div>';
|
||||
basketrel_html += '<div>Nouveau solde: '+newBalanceUKF+'</div>';
|
||||
if (newBalance < 0)
|
||||
basketrel_html += '<div>Manque: '+ (-newBalance).toFixed(2) +' €</div>';
|
||||
}
|
||||
basketrel_container.html(basketrel_html);
|
||||
}*/
|
||||
}
|
||||
|
||||
function deleteFromBasket(opeindex) {
|
||||
basket_container.find('[data-opeindex='+opeindex+']').remove();
|
||||
deleteFromFormset(opeindex);
|
||||
updateBasketRel();
|
||||
}
|
||||
|
||||
function resetBasket() {
|
||||
|
|
Loading…
Reference in a new issue