famille: widget for invoices and lines selection (#86611)
gitea/publik-base-theme/pipeline/head This commit looks good
Details
gitea/publik-base-theme/pipeline/head This commit looks good
Details
This commit is contained in:
parent
8e14778846
commit
98aaf3925f
|
@ -0,0 +1,122 @@
|
|||
{% extends "qommon/forms/widget.html" %}
|
||||
|
||||
{% block widget-control %}
|
||||
<ul class="template-invoice-lines--items" data-base-for-name="{{ widget.get_name_for_id }}_op_">
|
||||
{% for option in widget.get_options %}
|
||||
<li
|
||||
class="template-invoice-lines--item {% if option.disabled %}disabled{% endif %} {% if option.options.is_line %}invoice-line{% else %}invoice{% endif %}"
|
||||
{% if option.options.is_line %}
|
||||
data-related-invoice-id="{{ option.options.invoice_id }}" style="display:none"
|
||||
{% else %}
|
||||
data-invoice-id="{{ option.options.id }}"
|
||||
{% endif %}
|
||||
data-remaining-amount="{{ option.options.remaining_amount|multiply:100 }}"
|
||||
>
|
||||
<label for="{{ widget.get_name_for_id }}_op_{{ forloop.counter0 }}">
|
||||
<input
|
||||
id="{{ widget.get_name_for_id }}_op_{{ forloop.counter0 }}"
|
||||
{% if option.selected %}checked="checked"
|
||||
{% elif widget.readonly or option.disabled %}disabled{% endif %}
|
||||
{% for attr in widget.attrs.items %}{{attr.0}}="{{attr.1}}" {% endfor %}
|
||||
type="checkbox"
|
||||
{% if widget.readonly %}value="yes" disabled {% else %}name="{{ option.name }}" value="yes"{% endif %}
|
||||
>
|
||||
<span>
|
||||
{% if option.options.is_line %}
|
||||
{% if option.options.activity_label and option.options.activity_label != option.options.line_label %}
|
||||
{{ option.options.activity_label }} - {{ option.options.line_label }}
|
||||
{% else %}
|
||||
{{ option.options.line_label }}
|
||||
{% endif %}
|
||||
{% if option.options.details.check_type_label %}- {{ option.options.check_type_label }}{% elif option.options.status == 'absence' %}- Absence{% endif %}
|
||||
{% if option.options.line_description %}- {{ option.options.line_description }}{% endif %} :
|
||||
montant à régler de {{ option.options.remaining_amount|floatformat:"2" }} €
|
||||
{% else %}
|
||||
{{ option.options.display_id }} - {{ option.options.invoice_label }} :
|
||||
montant à régler de {{ option.options.remaining_amount|floatformat:"2" }} €
|
||||
{% endif %}
|
||||
</span>
|
||||
</label>
|
||||
{% if widget.readonly and option.selected %}<input type="hidden" name="{{ option.name }}" value="yes">{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<span class="template-invoice-lines--total-amount"></span>
|
||||
<style>
|
||||
.template-invoice-lines--item.invoice.selected {
|
||||
opacity: 0.5;
|
||||
}
|
||||
.template-invoice-lines--item.invoice-line {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
$('.template-invoice-lines--item.invoice input').on('change', function() {
|
||||
// when an invoice is checked/unchecked
|
||||
var $invoice = $(this);
|
||||
var $li = $invoice.parents('.template-invoice-lines--item')
|
||||
var invoice_id = $li.data('invoice-id');
|
||||
if ($invoice.is(':checked')) {
|
||||
// show and check related invoice lines
|
||||
$('input', $('.template-invoice-lines--item.invoice-line[data-related-invoice-id="' + invoice_id + '"]').show()).prop('checked', true);
|
||||
if ($('.template-invoice-lines--item.invoice-line').length) {
|
||||
$li.addClass('selected');
|
||||
} else {
|
||||
$li.removeClass('selected');
|
||||
}
|
||||
} else {
|
||||
// hide and uncheck related invoice lines
|
||||
$('input', $('.template-invoice-lines--item.invoice-line[data-related-invoice-id="' + invoice_id + '"]').hide()).prop('checked', false);
|
||||
$li.removeClass('selected');
|
||||
}
|
||||
});
|
||||
$('.template-invoice-lines--item.invoice-line input').on('change', function() {
|
||||
// when a line is checked/unchecked
|
||||
var $line = $(this);
|
||||
var invoice_id = $line.parents('.template-invoice-lines--item').data('related-invoice-id');
|
||||
if (! $('.template-invoice-lines--item.invoice-line[data-related-invoice-id="' + invoice_id + '"] input').is(':checked')) {
|
||||
// if all related lines are unchecked, uncheck invoice
|
||||
$('.template-invoice-lines--item.invoice[data-invoice-id="' + invoice_id + '"] input').prop('checked', false).trigger('change');
|
||||
}
|
||||
});
|
||||
compute_selected_amount = function() {
|
||||
// compute selected amount
|
||||
var sum = 0;
|
||||
if ($('.template-invoice-lines--item.invoice-line input').is(':checked')) {
|
||||
// if at least on line is checked, sum the selected lines
|
||||
$('.template-invoice-lines--item.invoice-line input:checked').each(function(index) {
|
||||
sum += parseFloat($(this).parents('.template-invoice-lines--item').data('remaining-amount'));
|
||||
});
|
||||
} else {
|
||||
// if no line checked, sum the selected invoices
|
||||
$('.template-invoice-lines--item.invoice input:checked').each(function(index) {
|
||||
sum += parseFloat($(this).parents('.template-invoice-lines--item').data('remaining-amount'));
|
||||
});
|
||||
}
|
||||
// sum is expressed in centimes, convert to euros
|
||||
sum = sum / 100
|
||||
sum = sum.toLocaleString(undefined, { maximumFractionDigits: 2, minimumFractionDigits: 2 });
|
||||
$('.template-invoice-lines--total-amount').html('Montant total sélectionné : ' + sum + ' €');
|
||||
};
|
||||
$('.template-invoice-lines--item input').on('change', function() {
|
||||
compute_selected_amount()
|
||||
});
|
||||
compute_selected_amount()
|
||||
// init visible invoice lines
|
||||
$('.template-invoice-lines--item.invoice input').each(function(index) {
|
||||
var $invoice = $(this);
|
||||
var $li = $invoice.parents('.template-invoice-lines--item')
|
||||
var invoice_id = $li.data('invoice-id');
|
||||
if ($invoice.is(':checked')) {
|
||||
$('.template-invoice-lines--item.invoice-line[data-related-invoice-id="' + invoice_id + '"]').show();
|
||||
if ($('.template-invoice-lines--item.invoice-line').length) {
|
||||
$li.addClass('selected');
|
||||
} else {
|
||||
$li.removeClass('selected');
|
||||
}
|
||||
} else {
|
||||
$li.removeClass('selected');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue