Upravy v programu a rozpoctu
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<a href="javascript:void(0);" data-toggle="modal" data-target="#addGroup">Přidat</a>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<% console.log(budget) %>
|
||||
<% for (var i in budget) { %>
|
||||
<!--<div class="col-md-4">-->
|
||||
<div class="card boxes__item budget" style="min-width: 25%; margin: 10px;" data-id="<%= i %>">
|
||||
@@ -29,12 +30,13 @@
|
||||
<h3><%= budget[i].name %></h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<input type="hidden" class="totalPrice" value="<%= budget[i].limit %>" />
|
||||
<% if (budget[i].items.length > 0) { %>
|
||||
<table class="table table-bordered table-striped table-hover">
|
||||
<tbody>
|
||||
|
||||
<% for (var j in budget[i].items) { %>
|
||||
|
||||
<% var item = budget[i].items[j]; %>
|
||||
<tr class="budget__item" <%= (j >= 4 ? 'hidden' : '') %>>
|
||||
<td>
|
||||
@@ -66,7 +68,7 @@
|
||||
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
CELKEM <span class="totalPrice"></span> Kč
|
||||
CELKEM <%= budget[i].limit %> Kč
|
||||
<div class="progress">
|
||||
<div class="progress-bar" role="progressbar">
|
||||
|
||||
@@ -77,8 +79,10 @@
|
||||
<!--</div>-->
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<% include ../partials/backend/modals/addItem.ejs %>
|
||||
|
||||
<% include ../partials/backend/modals/addItem.ejs %>
|
||||
<% include ../partials/backend/modals/addGroup.ejs %>
|
||||
<% include ../partials/backend/modals/budgetGroup.ejs %>
|
||||
|
||||
@@ -96,56 +100,83 @@
|
||||
method: 'get',
|
||||
success: function (response) {
|
||||
modal.find ('.modal-body').html (response);
|
||||
reinitBudgetProgressBars();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
function recalculateGroup($group) {
|
||||
var items = $group.find ('.budget__item');
|
||||
var priceTotal = 0, priceBought = 0;
|
||||
$ ('.modal').on ('hide.bs.modal', function (event) {
|
||||
$ ('.boxes__container').load ('/budget .boxes__container', function () {
|
||||
reinitBudgetProgressBars ();
|
||||
});
|
||||
});
|
||||
|
||||
items.each (function () {
|
||||
var bought = $ (this).find ('input[type=checkbox]');
|
||||
function recalculateGroup($group) {
|
||||
var items = $group.find ('.budget__item');
|
||||
var priceTotal = $group.find ('.totalPrice').val (), priceEstimation = 0, priceBought = 0;
|
||||
|
||||
var value = parseInt (bought.val ());
|
||||
items.each (function () {
|
||||
var bought = $ (this).find ('input[type=checkbox]');
|
||||
|
||||
priceTotal += value;
|
||||
if (bought.is (':checked')) {
|
||||
priceBought += value;
|
||||
}
|
||||
});
|
||||
var value = parseInt (bought.val ());
|
||||
|
||||
var remainingPercentage = priceBought / priceTotal * 100;
|
||||
var progressBarClass;
|
||||
if ($(this).find ('.price_field').length != 0) {
|
||||
value = parseInt ($(this).find ('.price_field').val ());
|
||||
}
|
||||
|
||||
if (remainingPercentage < 25) {
|
||||
progressBarClass = 'progress-bar-success';
|
||||
} else if (remainingPercentage < 50) {
|
||||
progressBarClass = 'progress-bar-info';
|
||||
} else if (remainingPercentage < 80) {
|
||||
progressBarClass = 'progress-bar-warning';
|
||||
} else {
|
||||
progressBarClass = 'progress-bar-danger';
|
||||
priceEstimation += value;
|
||||
if (bought.is (':checked')) {
|
||||
priceBought += value;
|
||||
}
|
||||
});
|
||||
|
||||
var remainingPercentage = priceBought / priceTotal * 100;
|
||||
var progressBarClass;
|
||||
|
||||
if (remainingPercentage < 25) {
|
||||
progressBarClass = 'progress-bar-success';
|
||||
} else if (remainingPercentage < 50) {
|
||||
progressBarClass = 'progress-bar-info';
|
||||
} else if (remainingPercentage < 80) {
|
||||
progressBarClass = 'progress-bar-warning';
|
||||
} else {
|
||||
progressBarClass = 'progress-bar-danger';
|
||||
}
|
||||
|
||||
$group.find ('.totalPrice').text (priceTotal);
|
||||
$group.find ('.progress-bar').text ("Zbývá " + (priceTotal - priceBought) + " Kč")
|
||||
var diff = (priceTotal - priceBought);
|
||||
|
||||
var progressBarText = "Zbývá " + diff + " Kč";
|
||||
if (diff < 0) {
|
||||
progressBarText = "Přečerpáno " + (diff * -1)+" Kč";
|
||||
}
|
||||
|
||||
$group.find ('.progress-bar').text (progressBarText)
|
||||
.css ('width', (remainingPercentage) + "%")
|
||||
.attr ('class', '')
|
||||
.addClass ('progress-bar')
|
||||
.addClass (progressBarClass);
|
||||
|
||||
|
||||
$group.find('.estimatedPrice').text(priceEstimation+" Kč");
|
||||
$group.find('.realPrice').text(priceBought+" Kč");
|
||||
|
||||
if (priceTotal == 0) {
|
||||
$group.find ('.card-footer').hide ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$ (document).ready (function () {
|
||||
$ ('.budget').each (function () {
|
||||
recalculateGroup ($ (this));
|
||||
});
|
||||
});
|
||||
function reinitBudgetProgressBars() {
|
||||
$ ('.budget').each (function () {
|
||||
recalculateGroup ($ (this));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$ (document).ready (reinitBudgetProgressBars);
|
||||
|
||||
$ (document).on ('change', '.totalPrice', reinitBudgetProgressBars);
|
||||
$ (document).on ('change', '.price_field', reinitBudgetProgressBars);
|
||||
|
||||
$ (document).on ('change', 'input[type=checkbox]', function () {
|
||||
|
||||
@@ -159,7 +190,7 @@
|
||||
method: 'post',
|
||||
data: 'bought=' + $ (this).is (':checked')
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user