<div class="card-body">

    [% if $WarantyRequestData.CallID %]
    <div  class="form-group row mb-3">
        <div class="col-lg-6">
            <label for="CallID" class="col-lg-3 control-label">[% $user->gettext('CallID') %]</label>
            <div class="col-lg-9">
                <input type="text" class="form-control"  id="CallID" value="[% $WarantyRequestData.CallID %]" readonly >
            </div>
        </div>
        <div class="col-lg-6">
            <label for="WarrantyRequestStatus" class="col-lg-3 control-label">[% $user->gettext('pA Status') %]</label>
            <div class="col-lg-9">
                <input type="text" class="form-control"  id="WarrantyRequestStatus" value="[% $WarantyRequestData.WarrantyRequestStatus %]" readonly >
            </div>
        </div>
    </div>
[% else %]
        <div  class="form-group row mb-3">
            <div class="col-lg-12">
                <p>[% $user->gettext('Übertragung fehlgeschlagen bitte an die Garantieabt. wenden') %]
                    [% $user->gettext('Klicken Sie hier um die Daten erneut zu übertragen.') %]
                    <span id="SentCallAction" class="btn btn-outline-secondary SentCallAction" title="[% $user->gettext('Daten erneut senden') %]" >
                        <span class="fa fa-repeat"></span>                        
                    </span>    
                </p> 
            </div>
        </div>
[% /if %]
    <div  class="form-group row mb-3">
        <label for="Type" class="col-lg-3 control-label">[% $user->gettext('Antragsart') %]</label>
        <div class="col-lg-9">
            <select name="WR[Type]" id="Type" class='form-control' disabled>
                <option value="">[% $user->gettext('Bitte wählen') %]</option>
                [%*
                <option value="0" [% if $WarantyRequestData.Type == 0 %]selected[% /if %] >[% $user->gettext('Wareneingangsf.') %]</option>
                <option value="1"[% if $WarantyRequestData.Type == 1 %]selected[% /if %] >[% $user->gettext('Kundenrückl.') %]</option>
                <option value="2" [% if $WarantyRequestData.Type == 2 %]selected[% /if %] >[% $user->gettext('Reparatur') %]</option>

                <option value="40" [% if $WarantyRequestData.Type == 40 %]selected[% /if %] >[% $user->gettext('AT-Antrag') %]</option>
                <option value="50" [% if $WarantyRequestData.Type == 50 %]selected[% /if %] >[% $user->gettext('Service Rundbrief') %]</option>
                <option value="70" [% if $WarantyRequestData.Type == 70 %]selected[% /if %] >[% $user->gettext('Techn. Anfrage') %]</option>
                <option value="75" [% if $WarantyRequestData.Type == 75 %]selected[% /if %] >[% $user->gettext('ET-Identifikat.') %]</option>
                <option value="80" [% if $WarantyRequestData.Type == 80 %]selected[% /if %] >[% $user->gettext('Schmiers.anf.') %]</option>

                *%]
                <option value="10" [% if $WarantyRequestData.Type == 10 || $WarantyRequestData.Type == 0 %]selected[% /if %] >[% $user->gettext('Garantie') %]</option>
                <option value="20" [% if $WarantyRequestData.Type == 20 %]selected[% /if %] >[% $user->gettext('Kulanz') %]</option>
                <option value="30" [% if $WarantyRequestData.Type == 30 %]selected[% /if %] >[% $user->gettext('ET-Reklamation') %]</option>
                <option value="60" [% if $WarantyRequestData.Type == 60 %]selected[% /if %]  disabled>[% $user->gettext('REMAN Antrag') %]</option>
                <option value="90" [% if $WarantyRequestData.Type == 90 %]selected[% /if %] disabled>[% $user->gettext('Retour') %]</option>
                <option value="50" [% if $WarantyRequestData.Type == 50 %]selected[% /if %] disabled>[% $user->gettext('Service Bulletin') %]</option>
                <option value="70" [% if $WarantyRequestData.Type == 70 %]selected[% /if %] disabled>[% $user->gettext('Techn. Anfrage') %]</option>
                <option value="75" [% if $WarantyRequestData.Type == 75 %]selected[% /if %] disabled>[% $user->gettext('ET-Identifikat.') %]</option>
                <option value="80" [% if $WarantyRequestData.Type == 80 %]selected[% /if %] disabled>[% $user->gettext('Schmiers.anf.') %]</option>
                <option value="1" [% if $WarantyRequestData.Type == 1 %]selected[% /if %] disabled>[% $user->gettext('Kundenrückl.') %]</option>
                <option value="2" [% if $WarantyRequestData.Type == 2 %]selected[% /if %] disabled>[% $user->gettext('Reparatur') %]</option>   
            </select>
        </div>
    </div>


    <div  class="form-group row mb-3">
        <label for="expires" class="col-lg-3 control-label">[% $user->gettext('VorgangsnummerKunde') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control"  id="TransactionNumberCustomer" name="WR[TransactionNumberCustomer]"  value="[% if $WarantyRequestData.TransactionNumberCustomer %][% $WarantyRequestData.TransactionNumberCustomer %][% /if %]" readonly >
        </div>
    </div>

    <div  class="form-group row mb-3">
        <label for="DamageDescription" class="col-lg-3 control-label">[% $user->gettext('Schadensbeschreibung') %]</label>
        <div class="col-lg-9">
            <textarea class="form-control"  id="DamageDescription" name="WR[DamageDescription]"  maxlength="4000" style="height:200px;" readonly>[% if $WarantyRequestData.DamageDescription %][% $WarantyRequestData.DamageDescription %][% /if %]</textarea>            
        </div>
    </div>
    <div  class="form-group row mb-3">
        <label for="DamageRepair" class="col-lg-3 control-label">[% $user->gettext('Schadensbehebung') %]</label>
        <div class="col-lg-9">
            <textarea class="form-control"  id="DamageRepair" name="WR[DamageRepair]"  maxlength="4000" style="height:200px;" readonly>[% if $WarantyRequestData.DamageRepair %][% $WarantyRequestData.DamageRepair %][% /if %]</textarea>
        </div>
    </div>


    <div  class="form-group row mb-3">
        <label for="EntryDate" class="col-lg-3 control-label">[% $user->gettext('Erfassungsdatum') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control datepicker_disabled"  id="EntryDate" name="WR[EntryDate]"  value="[% if $WarantyRequestData.EntryDate %][% $WarantyRequestData.EntryDate|date_format:"%d.%m.%Y" %][% /if %]" readonly="readonly" >
        </div>
    </div>
    <div  class="form-group row mb-3">
        <label for="DamageOccurrenceDate" class="col-lg-3 control-label">[% $user->gettext('Schadenseintrittsdatum') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control datepicker_disabled"  id="DamageOccurrenceDate" name="WR[DamageOccurrenceDate]"  value="[% if $WarantyRequestData.DamageOccurrenceDate %][% $WarantyRequestData.DamageOccurrenceDate|date_format:"%d.%m.%Y" %][% /if %]" readonly="readonly" >
        </div>
    </div>
    <div  class="form-group row mb-3">
        <label for="RepairEndDate" class="col-lg-3 control-label">[% $user->gettext('Reparaturende Datum') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control datepicker_disabled"  id="RepairEndDate" name="WR[RepairEndDate]"  value="[% if $WarantyRequestData.RepairEndDate %][% $WarantyRequestData.RepairEndDate|date_format:"%d.%m.%Y" %][% /if %]" readonly="readonly" >
        </div>

    </div>
[%*
    <div  class="form-group row mb-3">
        <label for="OperatingHoursDamageOccurrence" class="col-lg-3 control-label">[% $user->gettext('Betriebsstunden bei Schadenseintritt') %]</label>
        <div class="col-lg-9">
            <input type="number" class="form-control"  id="OperatingHoursDamageOccurrence" name="WR[OperatingHoursDamageOccurrence]"  value="[% if $WarantyRequestData.OperatingHoursDamageOccurrence %][% $WarantyRequestData.OperatingHoursDamageOccurrence %][% /if %]"   readonly="readonly" >
        </div>
    </div>
*%]

    <div  class="form-group row mb-3">
        <label for="DealerID" class="col-lg-3 control-label">[% $user->gettext('HändlerID') %]</label>
        <div class="col-lg-9">
            <input type="number" class="form-control"  id="DealerID" name="WR[DealerID]"  value="[% if $WarantyRequestData.DealerID %][% $WarantyRequestData.DealerID %][% /if %]"   readonly="readonly" >
        </div>
    </div>
    <div  class="form-group row mb-3">
        <label for="CustomerID" class="col-lg-3 control-label">[% $user->gettext('EndkundenID') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control"  id="CustomerID" name="WR[CustomerID]"  value="[% if $WarantyRequestData.CustomerID %][% $WarantyRequestData.CustomerID %][% /if %]"   readonly="readonly" >
        </div>
    </div>
    [% if $WarantyRequestData.Type == 30 %]
    <div  class="form-group row mb-3 visibleForCallTypeETRecla">
        <label for="ETBetriebsstunden" class="col-lg-3 control-label">[% $user->gettext('Betriebsstunden Bauteil (ET)') %]</label>
        <div class="col-lg-9">
            <input type="number" class="form-control"  id="ETBetriebsstunden" name="WR[ETBetriebsstunden]"  value="[% if $WarantyRequestData.ETBetriebsstunden %][% $WarantyRequestData.ETBetriebsstunden %][% /if %]"   readonly="readonly" >
        </div>
    </div>
    <div  class="form-group row mb-3 visibleForCallTypeETRecla">
        <label for="ETInbetriebnahme" class="col-lg-3 control-label">[% $user->gettext('Inbetriebnahme Bauteil (ET)') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control datepicker_disabled"  id="ETInbetriebnahme" name="WR[ETInbetriebnahme]"  value="[% if $WarantyRequestData.ETInbetriebnahme %][% $WarantyRequestData.ETInbetriebnahme|date_format:"%d.%m.%Y" %][% /if %]" readonly="readonly" >
        </div>
    </div>
    [% /if %]
    <hr/>
    <div  class="form-group row mb-3">
        <label for="Motornummer" class="col-lg-3 control-label">[% $user->gettext('Motornummer (Maschine)') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control"  id="Motornummer" name="WR[Motornummer]"  value="[% if $WarantyRequestData.Motornummer %][% $WarantyRequestData.Motornummer %][% /if %]"   readonly="readonly" >
        </div>
    </div>
    <div  class="form-group row mb-3">
        <label for="Inbetriebnahmedatum" class="col-lg-3 control-label">[% $user->gettext('Inbetriebnahmedatum (Maschine)') %]</label>
        <div class="col-lg-9">
            <input type="text" class="form-control datepicker_disabled"  id="Inbetriebnahmedatum" name="WR[Inbetriebnahmedatum]"  value="[% if $WarantyRequestData.Inbetriebnahmedatum %][% $WarantyRequestData.Inbetriebnahmedatum|date_format:"%d.%m.%Y" %][% /if %]" readonly="readonly" >
        </div>
    </div>


    <div class="card panel-info shadow-sm rounded">
        <div class="card-header" role="tab" style="cursor:default">
            <div class="row">
                <div class="col-sm-6">
                     <h6 class="card-title">
                        [% $user->gettext('Artikel und Arbeitskosten hinzufügen') %]
                    </h6>
                </div>
                <div class="col-sm-6 text-end">
                    [% if $WarantyRequestData.PositionsEditable || $WarantyRequestData == null || $WarantyRequestData.CallID == 0 %]

                       [% if $user->hasRight(260) || $user->inGroup(1)  %]
                            <span class="btn btn-outline-secondary" id="togglePositionsEditable"><span class="fa fa-ban"></span> [% $user->gettext('Artikel und Arbeitskosten zur Bearbeitung sperren') %]</span>
                        [% /if %]                        
                    [% else %]
                       [% if $user->hasRight(260) || $user->inGroup(1) %]
                            <span class="btn btn-outline-secondary" id="togglePositionsEditable"><span class="fa fa-check"></span> [% $user->gettext('Artikel und Arbeitskosten zur Bearbeitung freigeben') %]</span>
                        [% else %]
                            <span class="fa fa-ban" title="[% $user->gettext('Das Ändern von Artikel oder Arbeitskosten ist in diesem Antrag nicht möglich') %]"></span>
                        [% /if %]
                    
                    [% /if %]
                </div>
                
            </div>
        </div>

        <div class="card-body">
            [% if $WarantyRequestData.PositionsEditable || $WarantyRequestData == null || $WarantyRequestData.CallID == 0 %]
                <div class="row">
                    <div class="col-lg-6">
                        <input type="button" class="btn btn-outline-secondary" value="[% $user->gettext('Artikel- / Arbeitskostenauswahl öffnen') %]" onclick="GetPositionSelection();" />
                    </div>
                </div>
            [%*

            <div class="row">
                <div class="col-lg-6">
                    <h3>[% $user->gettext('Artikel- / Arbeitskosten suchen über') %]</h3>
                    <div class="row">
                        <div class="col-lg-6">
                            <input class="form-check-input" type="radio" name="rbtnbSearch" id="rdbSearchInvoice" checked>
                            <label class="form-check-label" for="rdbSearchInvoice">[% $user->gettext('Rechnungsnummer') %]</label>
                            <br/>
                            <input class="form-check-input" type="radio" name="rbtnbSearch" id="rdbSearchArticle">
                            <label class="form-check-label" for="rdbSearchArticle">[% $user->gettext('Artikelnummer') %]</label>
                        </div>
                        <div class="col-lg-6">

                            [% if $user->getPaKDNRs() > 1 %]
                                <label>[% $user->gettext('Kunde') %]</label>
                                <select id="paKDNR" name="paKDNR" class="form-control" data-width="100%">
                                     <option value="" disabled selected>[% $user->gettext('proAlpha Kunden wählen') %]</option>
                                    [% foreach from=$user->getPaKDNRs() item=group key=kdnr %]
                                        <option value="[% $kdnr %]" [% if $ticket.padealerid == $kdnr %]selected[% /if %]>[% $group %]</option>
                                    [% /foreach %]
                                </select>
                            [% else %]
                                <input type="text" id="paKDNR" name="paKDNR" class="form-control" placeholder="[% $user->gettext('proAlpha Kundennummer eingeben') %]" [% if $ticket.padealerid %]value="[% $ticket.padealerid %]"[% /if %]>
                            [% /if %]
                            <input type="text" id="SearchValue" class="form-control" placeholder="[% $user->gettext('Rechnungs- oder Artikelnr.') %]"/>
                            <input type="button" class="btn btn-outline-primary" value="[% $user->gettext('Artikel hinzufügen') %]" onclick="GetInvoices();" />
                        </div>
                    </div>
                </div>
            </div>
            *%]

            [% /if %]

            <div class="card-body" id="SavedPositionList">[% include file=$modulePath|cat:"/TicketWPRequestPositions.tpl" %]</div>
            
        </div>
    </div>
</div>
<script>

    [% if $user->hasRight(260) || $user->inGroup(1) %]
        $('#togglePositionsEditable').on('click', function (e) {
            $.post('index.php?module=ticket&event=togglePositionsEditable', {tid: TicketID}, function (data){
                if(data == 1){
//                    UpdateCall();
                    location.reload();
                }
            })
        });
    [% /if %]

function GetPositionSelection(){
    $("#PositionSelectionModal").modal("show");
}
    </script>
