<?php 

use Jackiedo\DotenvEditor\Facades\DotenvEditor;

$editor = DotenvEditor::load(storage_path('app/settings.env'));

?>
<form id="new_manhour">
    <input type="hidden" name="data[_manhours_at_tickets]" value="{{$model->getAttribute('_manhours_at_tickets')}}">
    
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" style="width:160px;">Beschreibung</span>
        </div>
        <textarea class="form-control" name="data[descriptor]" autocomplete="off" autofocus></textarea>
        <div class="input-group-append">
            <button class="btn btn-info" type="button" id="open_manhourunits_button">Auswahl ..</button>
        </div>
    </div>
    
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            @if(1==request('offer'))
            <span class="input-group-text" style="width:160px;">geplante Stunden</span>
            @else
            <span class="input-group-text" style="width:160px;">geleistete Stunden</span>
            @endif
        </div>
        <input type="text" class="form-control" name="data[workinghours]" autocomplete="off" oninput="this.value = this.value.replace(/[^\d,-]+/g, '')">
    </div>

    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" style="width:160px;">geleistetet durch</span>
        </div>
            <select class="custom-select" name="data[_staff]">
            <option>Mitarbeiter ..</option>
            @foreach(\App\Models\PHPXPress\HwplusStaff::get() AS $row)
            <option value="{{$row->ID}}" @if(\App\Models\PHPXPress\Users::find(\Auth::user()->getKey())->_user_at_hwplus_staff->getKey() == $row->getKey()) selected @endif>{{$row->descriptor}}</option>
            @endforeach
        </select>
    </div>
    
    @if(1==request('offer'))
    @else
    
    <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" style="width:160px;">geleistet am</span>
        </div>
         <input type="date" class="form-control" name="data[date]" value="{{\Carbon\Carbon::now()->format('Y-m-d')}}">
    </div>
    
    @endif
    
    <div class="input-group mb-3">
     <span class="input-group-text"  style="width:160px;">Fahrtkosten ber.</span>
        <div class="input-group-append">
        <div class="input-group-text">
            <input class="--form-check-input" type="checkbox" id="defaultCheck1" value="1" onclick="$('#fare').val( !this.checked ? 0 : 1 ) ">
            <input type="hidden" name="data[fare]" id="fare" value="0"/>
        </div>
    </div>
    </div>
  
    @if(1==request('offer'))

    <div class="input-group mb-3">
     <span class="input-group-text"  style="width:160px;">Preis überschreiben</span>
        <div class="input-group-append">
        <div class="input-group-text">
            <input class="" type="checkbox" onchange="$('fieldset').toggleClass('d-none') ">
        </div>
    </div>
    </div>

    <fieldset class="d-none">

        Diese Option überschreibt den aus dem Stundensatz des Mitarbeiters automatisch kalkulierten Betrag.

        <div class="input-group mt-3 mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" style="width:160px;">MwSt.</span>
            </div>
            <select class="custom-select" id="vat_rate" name="data[vat]" style="width:10%;">
                    @if(!$editor->getValue('COMPANY_SBLAW'))
                    @foreach(\Runtime::make('hwplus_vat_rates')->get() AS $rate)
                    <option value="{{$rate->rate}}" @if($rate->flag_default) selected @endif>{{$rate->descriptor}}</option>
                    @endforeach
                    @else
                    <option value="0">0%</option>
                    @endif
                </select>
        </div>

        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" style="width:160px;">Einzelpreis</span>
            </div>
            <input type="text" class="form-control" name="data[netprice]" placeholder="€" autocomplete="off" oninput="this.value = this.value.replace(/[^\d,-]+/g, '')">
        </div>

    </fieldset>

    @endif

</form>

<script>
    $('input[name="data[descriptor]"]').focus();
</script>
