Files
interblue.pl/modules/przelewy24/views/js/admin_common.js
2024-10-25 14:16:28 +02:00

44 lines
1.1 KiB
JavaScript

/*
* @author Przelewy24
* @copyright Przelewy24
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
*/
$(function() {
let $targetInput = $('#p24-amount-to-refund ');
let $lines = $('#p24-refund-form input.js-line')
let recount = function ()
{
let newVal = 0;
$lines.each(function(idx, elm) {
let $elm = $(elm);
let q = $elm.val();
let p = $elm.data('unit-price');
newVal += q * p;
newVal = Math.round(newVal * 100) / 100;
});
newVal = Math.min(newVal, $targetInput.data('maximum'));
$targetInput.val(newVal);
}
let reset = function ()
{
$lines.each(function(idx, elm) {
let $elm = $(elm);
$elm.val(0);
});
}
$lines.on('change', recount);
$targetInput.on('change', reset);
});
$(function () {
let needReloadRefund = $('#p24-need-reload-refund').data('need');
if (needReloadRefund) {
location = location.protocol + '//' + location.host + location.pathname + location.search;
}
});