{% extends '@!EasyAdmin/page/content.html.twig' %}
{% block page_content %}
<div class="payview">
<h2>{{worker}}
<select id="workerDateSelect" class="form-control form-control-sm col-3 d-inline ml-auto" style="width: 30%; float:right;" onchange="changeYear()">
{% for w in workerDates %}
<option {{ (selectedDate and w == selectedDate) ? 'selected' : '' }} data-url="{{ (ea_url().setController('App\\Controller\\Admin\\WorkersCrudController').setAction('actionPaid').setEntityId(worker.id)) ~ '&date=' ~ w|url_encode }}">{{w}}</option>
{% endfor %}
</select>
{% if isAdmin %}
<select id="workerSelect" class="form-control form-control-sm col-3 d-inline ml-auto" style="width: 30%; float:right;" onchange="changeWorker()">
{% for w in workers %}
<option {{ w.id == worker.id ? 'selected' : '' }} value="{{w.id}}" {% if w.id == worker.id %}selected{% endif %} data-url="{{ (ea_url().setController('App\\Controller\\Admin\\WorkersCrudController').setAction('actionPaid').setEntityId(w.id)) ~ '?date=' ~ ((selectedDate ?: (workerDates[0] ?? ''))|url_encode) }}">{{w.fullName}}</option>
{% endfor %}
</select>
{% endif %}
</h2> <table class="table">
{% set sum=0 %}
{% set sumHour=0 %}
{% set sumOther=0 %}
<tr>
<th width="20px">Fizetve</th>
<th>Projekt</th>
<th>Idő</th>
<th>Órabér</th>
<th>Egyéb költség</th>
<th>Összesen</th>
<th>Nap</th>
<th>Létrehozva</th>
</tr>
{% for hour in hours %}
<tr id="row-{{hour.id}}">
<td class="text-center"><span class="fa text-success fa-{{(hour.payed == true)? "coins": ""}}"></span></td>
{% if hour.project %}
{% if hour.project.customer %}
<td>({{hour.project.customer.name}}) {{hour.project.name}} - {{hour.note|raw}}</td>
{% else %}
<td>{{hour.project.name}} - {{hour.note|raw}}</td>
{% endif %}
{% else %}
<td>{{hour.note|raw}}</td>
{% endif %}
<td id="hour-{{hour.id}}">{{hour.hours}} ó</td>
<td id="hp-{{hour.id}}">{{hour.payedHourPrice|format_currency('HUF', {rounding_mode: 'floor', fraction_digit: 0})}}</td>
<td id="other-{{hour.id}}">{{hour.otherPrice|format_currency('HUF', {rounding_mode: 'floor', fraction_digit: 0})}}</td>
<td class="text-right" style="padding-right: 3rem !important;" id="sum-{{hour.id}}">{{((hour.hours*worker.priceHour)+hour.otherPrice)|format_currency('HUF', {rounding_mode: 'floor', fraction_digit: 0})}}</td>
<td>{{hour.day?hour.day.format('Y-m-d'):'-'}}</td>
<td>{{hour.created.format('Y-m-d')}}</td>
{% set sumHour = sumHour + hour.hours %}
{% set sum = sum + (hour.hours * hour.payedHourPrice) %}
{% set sumOther = sumOther + (hour.otherPrice?hour.otherPrice:0) %}
</tr>
{% endfor %}
<tfoot style="background-color: #fafafafa">
<tr>
<td colspan="2"><strong>Összesen</strong></td>
<td id="sumHours" >{{sumHour}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong>Fizetendő óra</strong></td>
<td id="sumHoursPrice">{{(sum)|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong>Egyéb költség</strong></td>
<td id="sumOther">{{sumOther|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong>Teljes fizetendő összeg</strong></td>
<td><strong id="sumTotalStrong">{{((sum)+sumOther)|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</strong></td>
<td><input type="hidden" name="sumTotal" id="sumTotal" value="{{(sum)+sumOther}}"></td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
<script type="text/javascript">
(function(){
window.changeWorker = function(){
var select = document.getElementById('workerSelect');
var dateSelect = document.getElementById('workerDateSelect');
var selectedDate = dateSelect ? dateSelect.value : '';
var url = select.options[select.selectedIndex].dataset.url;
if (url && selectedDate) {
var target = new URL(url, window.location.origin);
target.searchParams.set('date', selectedDate);
window.location.href = target.toString();
return;
}
if (url) {
window.location.href = url;
}
};
window.changeYear = function(){
var select = document.getElementById('workerDateSelect');
var url = select.options[select.selectedIndex].dataset.url;
if (url) {
window.location.href = url;
}
};
})();
function check(){
$('#sumTotal').val(0);
var total = 0;
var sumHours = 0;
var sumHoursPrice = 0;
var sumOther = 0;
var priceHour = parseInt($('#priceHour').val())
$('.hour-checkbox:checked').each(function(key,chk){
var price = parseInt($('#sum-'+chk.value).html())
var other = parseInt($('#other-'+chk.value).html())
var hour = parseFloat($('#hour-'+chk.value).html())
total = total + price;
if(other > 0){
sumOther = sumOther + other;
}
sumHours = sumHours + hour;
sumHoursPrice = sumHoursPrice + (hour*priceHour);
$('#sumTotalStrong').html(total);
$('#sumOther').html(sumOther);
$('#sumHours').html(sumHours);
$('#sumHoursPrice').html(sumHoursPrice);
})
}
</script>
</div>
{% endblock page_content %}