{% extends '@!EasyAdmin/page/content.html.twig' %}
{% block page_content %}
<div>
<h2>{{worker}}</h2>
<form method="post">
<table class="table">
{% set sum=0 %}
{% set sumOther=0 %}
<tr>
<th>Kifizet</th>
<th>Projekt</th>
<th>Idő</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}}">
{% if hour.isValidated %}
<td><input type="checkbox" value="{{hour.id}}" checked="" name="workhours[]" class="hour-checkbox" onClick="check()"></td>
{% else %}
<td><input type="checkbox" value="{{hour.id}}" name="workhours[]" class="hour-checkbox" onClick="check()"></td>
{% endif %}
{% 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="other-{{hour.id}}">{{hour.otherPrice}}</td>
<td id="sum-{{hour.id}}">{{(hour.hours*worker.priceHour)+hour.otherPrice}}</td>
<td>{{hour.day?hour.day.format('Y-m-d'):'-'}}</td>
<td>{{hour.created.format('Y-m-d')}}</td>
{% if hour.isValidated %}
{% set sum = sum + hour.hours %}
{% set sumOther = sumOther + (hour.otherPrice?hour.otherPrice:0) %}
{% endif %}
</tr>
{% endfor %}
<tfoot style="background-color: #fafafafa">
<tr>
<td colspan="2"><strong>Összesen</strong></td>
<td id="sumHours" >{{sum}}</td>
<td id="sumHours" >{{sum}}</td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong>Órabér</strong></td>
<td>{{worker.priceHour|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</td>
<td><input type="number" name="priceHour" id="priceHour" value="{{worker.priceHour}}"></td>
<td><input type="number" name="priceHour" id="priceHour" value="{{worker.priceHour}}"></td>
</tr>
<tr>
<td colspan="2"><strong>Fizetendő óra</strong></td>
<td id="sumHoursPrice">{{(sum*worker.priceHour)|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</td>
<td colspan="2"><strong>Fizetendő óra</strong></td>
<td id="sumHoursPrice">{{(sum*worker.priceHour)|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</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 id="sumOther">{{sumOther|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</td>
<td></td>
</tr>
<tr>
<td colspan="2"><strong>Teljes fizetendő összeg</strong></td>
<td><strong id="sumTotalStrong">{{((sum*worker.priceHour)+sumOther)|format_currency('HUF',{fraction_digit: 0}, locale='hu')}}</strong></td>
<td><input type="hidden" name="sumTotal" id="sumTotal" value="{{(sum*worker.priceHour)+sumOther}}"></td>
</tr>
</tfoot>
</table>
<input type="submit" name="submit" value="Fizetés" class="btn btn-info">
</form>
<script type="text/javascript">
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>
<script type="text/javascript">
function check(){
var sumTotal = document.getElementById('sumTotal')
sumTotal.value = 0;
var total = 0;
var sumHours = 0;
var sumHoursPrice = 0;
var sumOther = 0;
var priceHour = document.getElementById('priceHour')
var priceHour = parseInt(priceHour.value)
var checked = document.querySelectorAll('.hour-checkbox:checked')
checked.forEach(function(chk, key){
console.log(key, chk, chk.value)
var price = parseInt(document.getElementById('sum-'+chk.value).innerHTML)
var other = parseInt(document.getElementById('other-'+chk.value).innerHTML)
var hour = parseFloat(document.getElementById('hour-'+chk.value).innerHTML)
total = total + price;
if(other > 0){
sumOther = sumOther + other;
}
sumHours = sumHours + hour;
sumHoursPrice = sumHoursPrice + (hour*priceHour);
document.getElementById('sumTotalStrong').innerHTML = total;
document.getElementById('sumOther').innerHTML = sumOther;
document.getElementById('sumHours').innerHTML = sumHours;
document.getElementById('sumHoursPrice').innerHTML = sumHoursPrice;
})
}
</script>
</div>
{% endblock page_content %}