Page Historique
- Reprise du JS d'historique dans `kfet/static/kfet/js/history.js` - Adapatation de K-Psul pour l'utiliser - Création page historique avec filtres (dates, caisses, comptes)
This commit is contained in:
parent
b380984a1e
commit
3b7c690f0b
9 changed files with 328 additions and 153 deletions
108
kfet/static/kfet/js/history.js
Normal file
108
kfet/static/kfet/js/history.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
function KHistory(options={}) {
|
||||
$.extend(this, KHistory.default_options, options);
|
||||
|
||||
this.$container = $(this.container);
|
||||
|
||||
this.reset = function() {
|
||||
this.$container.html('');
|
||||
};
|
||||
|
||||
this.addOpeGroup = function(opegroup) {
|
||||
var $day = this._getOrCreateDay(opegroup['at']);
|
||||
var $opegroup = this._opeGroupHtml(opegroup);
|
||||
|
||||
$day.after($opegroup);
|
||||
|
||||
var trigramme = opegroup['on_acc_trigramme'];
|
||||
var is_cof = opegroup['is_cof'];
|
||||
for (var i=0; i<opegroup['opes'].length; i++) {
|
||||
var $ope = this._opeHtml(opegroup['opes'][i], is_cof, trigramme);
|
||||
$ope.data('opegroup', opegroup['id']);
|
||||
$opegroup.after($ope);
|
||||
}
|
||||
}
|
||||
|
||||
this._opeHtml = function(ope, is_cof, trigramme) {
|
||||
var $ope_html = $(this.template_ope);
|
||||
var parsed_amount = parseFloat(ope['amount']);
|
||||
var amount = amountDisplay(parsed_amount, is_cof, trigramme);
|
||||
var infos1 = '', infos2 = '';
|
||||
|
||||
if (ope['type'] == 'purchase') {
|
||||
infos1 = ope['article_nb'];
|
||||
infos2 = ope['article__name'];
|
||||
} else {
|
||||
infos1 = parsed_amount.toFixed(2)+'€';
|
||||
infos2 = (ope['type'] == 'deposit') ? 'Charge' : 'Retrait';
|
||||
}
|
||||
|
||||
$ope_html
|
||||
.data('ope', ope['id'])
|
||||
.find('.amount').text(amount).end()
|
||||
.find('.infos1').text(infos1).end()
|
||||
.find('.infos2').text(infos2).end();
|
||||
|
||||
var addcost_for = ope['addcost_for__trigramme'];
|
||||
if (addcost_for) {
|
||||
var addcost_amount = parseFloat(ope['addcost_amount']);
|
||||
$ope_html.find('.addcost').text('('+amountDisplay(addcost_amount, is_cof)+'UKF pour '+addcost_for+')');
|
||||
}
|
||||
|
||||
if (ope['canceled_at']) {
|
||||
var canceled_at = dateUTCToParis(ope['canceled_at']);
|
||||
var canceled_by = ope['canceled_by__trigramme'];
|
||||
var cancel = 'Annulé';
|
||||
if (canceled_by)
|
||||
cancel += ' par '+canceled_by;
|
||||
cancel += ' le '+canceled_at.format('DD/MM/YY à HH:mm:ss');
|
||||
$ope_html.addClass('canceled').find('.canceled').text(cancel);
|
||||
}
|
||||
|
||||
return $ope_html;
|
||||
}
|
||||
|
||||
this._opeGroupHtml = function(opegroup) {
|
||||
var $opegroup_html = $(this.template_opegroup);
|
||||
|
||||
var at = dateUTCToParis(opegroup['at']).format('HH:mm:ss');
|
||||
var trigramme = opegroup['on_acc__trigramme'];
|
||||
var amount = amountDisplay(
|
||||
parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme);
|
||||
var comment = opegroup['comment'] || '';
|
||||
|
||||
$opegroup_html
|
||||
.data('opegroup', opegroup['id'])
|
||||
.find('.time').text(at).end()
|
||||
.find('.amount').text(amount).end()
|
||||
.find('.comment').text(comment).end();
|
||||
|
||||
if (this.display_trigramme)
|
||||
$opegroup_html.find('.trigramme').text(trigramme);
|
||||
|
||||
if (opegroup['valid_by__trigramme'])
|
||||
$opegroup_html.find('.valid_by').text('Par '+opegroup['valid_by__trigramme']);
|
||||
|
||||
|
||||
return $opegroup_html;
|
||||
}
|
||||
|
||||
this._getOrCreateDay = function(date) {
|
||||
var at = dateUTCToParis(date);
|
||||
var at_ser = at.format('YYYY-MM-DD');
|
||||
var $day = this.$container.find('.day').filter(function() {
|
||||
return $(this).data('date') == at_ser
|
||||
});
|
||||
if ($day.length == 1)
|
||||
return $day;
|
||||
var $day = $(this.template_day).prependTo(this.$container);
|
||||
return $day.data('date', at_ser).text(at.format('D MMMM'));
|
||||
}
|
||||
}
|
||||
|
||||
KHistory.default_options = {
|
||||
container: '#history',
|
||||
template_day: '<div class="day"></div>',
|
||||
template_opegroup: '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
|
||||
template_ope: '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
|
||||
display_trigramme: true,
|
||||
}
|
|
@ -8,4 +8,35 @@ $(document).ready(function() {
|
|||
$('.col-content-right').removeClass('col-sm-offset-4 col-md-offset-3');
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieving csrf token
|
||||
var csrftoken = Cookies.get('csrftoken');
|
||||
// Appending csrf token to ajax post requests
|
||||
function csrfSafeMethod(method) {
|
||||
// these HTTP methods do not require CSRF protection
|
||||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
|
||||
}
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr, settings) {
|
||||
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
|
||||
xhr.setRequestHeader("X-CSRFToken", csrftoken);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function dateUTCToParis(date) {
|
||||
return moment.tz(date, 'UTC').tz('Europe/Paris');
|
||||
}
|
||||
|
||||
function amountDisplay(amount, is_cof=false, tri='') {
|
||||
if (tri == 'LIQ')
|
||||
return (- amount).toFixed(2) +'€';
|
||||
return amountToUKF(amount, is_cof);
|
||||
}
|
||||
|
||||
function amountToUKF(amount, is_cof=false) {
|
||||
var coef_cof = is_cof ? 1 + settings['subvention_cof'] / 100 : 1;
|
||||
return Math.round(amount * coef_cof * 10);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue