
<div id="InvoicesModal" class="modal fade" style="padding-right:0px;  z-index:9999; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
     -moz-box-sizing: border-box;    /* Firefox */
     box-sizing: border-box;">
    <div class="modal-dialog modal-lg" style=" width:80vw;">
        <div class="modal-content">
            <div class="modal-header hidden-print" style="background-color:#f5f5f5; padding:0px; border-bottom: 0px; ">
                <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true" style="color:black; font-size:2.0em; margin-right:10px; opacity: 1.0;"><span style="color:black;">&times;</span></button>

            </div>
            <div class="modal-body" style="padding:0px;">
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <h3 class="fcs-card-title h3">[% $entries %] [% $user->gettext('Positionen') %]</h3>
                    </div>
                    <div class="card-body">
                        <div class="card-body" id="InvoicePositionListAA">

                        </div>                   
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="WagesModal" class="modal fade" style="padding-right:0px;  z-index:9999; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
     -moz-box-sizing: border-box;    /* Firefox */
     box-sizing: border-box;">
    <div class="modal-dialog modal-lg" style=" width:80vw;">
        <div class="modal-content">
            <div class="modal-header hidden-print" style="background-color:#f5f5f5; padding:0px; border-bottom: 0px; ">
                <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true" style="color:black; font-size:2.0em; margin-right:10px; opacity: 1.0;"><span style="color:black;">&times;</span></button>

            </div>
            <div class="modal-body" style="padding:0px;">
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <h3 class="card-title">[% $entries %] [% $user->gettext('Einträge') %]</h3>
                    </div>
                    <div class="card-body">
                        <div class="card-body" id="WagePositionList">
                        </div>
                        <div class="btn-group" style="float: right;">
                            <span class="btn btn-outline-success" id="SaveWagePositions" data-toggle="button" aria-pressed="false" autocomplete="off" title="[% $user->gettext('Speichern') %]" onclick="SaveWagePositions();">[% $user->gettext('Speichern') %]</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="WPRPositionModal" class="modal fade" style="padding-right:0px;  z-index:9999; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
     -moz-box-sizing: border-box;    /* Firefox */
     box-sizing: border-box;">
    <div class="modal-dialog modal-lg" style=" width:80vw;">
        <div class="modal-content">
            <div class="modal-header hidden-print FrameModalHeader">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

            </div>
            <div class="modal-body" style="padding:0px;">
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <h3 class="card-title">[% $entries %] [% $user->gettext('Dokumente') %]</h3>
                    </div>
                    <div class="card-body">
                        <div class="card-body" id="DocumentsList">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<div id="PositionSelectionModal" class="modal fade" style="padding-right:0px;  z-index:9999; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
     -moz-box-sizing: border-box;    /* Firefox */
     box-sizing: border-box;">
    <div class="modal-dialog" style="max-width: 80%;">
        <div class="modal-content" style="height:90vh;min-height:200px;">
            <div class="modal-header hidden-print" style="background-color:#f5f5f5; padding:0px; border-bottom: 0px; ">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding:0px;">
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-2">
                                <span class="fcs-card-title h3">[% $user->gettext('Positionen') %]</span>
                            </div>
                            <div class="col-sm-8">

                                <div class="row inline-form" id="PositionSearchForm">
                                    <div class="col-sm-3">
                                        [% if $user->getPaKDNRs() > 1 %]
                                            <select id="paKDNR" name="paKDNR" class="form-control" data-width="100%">
                                                <option value="" disabled selected>[% $user->gettext('Kunden wählen') %]</option>
                                                [% foreach from=$user->getPaKDNRs() item=group key=kdnr %]
                                                    <option value="[% $kdnr %]" [% if $kdnr == $ticket.padealerid %]selected[% /if %]>[% $group %]</option>
                                                [% /foreach %]
                                            </select>
                                        [% else %]
                                            <input type="text" id="paKDNR" name="paKDNR" class="form-control" placeholder="[% $user->gettext('Kundennummer eingeben') %]">                                                
                                        [% /if %]
                                    </div>
                                    <div class="col-sm-3">
                                        <select id="PositionsSource" class="form-control">
                                            <option value="rdbSearchInvoice">[% $user->gettext('RechnungsNr') %]</option>
                                            <option value="rdbSearchArticle">[% $user->gettext('ArtikelNr') %]</option>
                                            <option value="SelectWagePositions">[% $user->gettext('Arbeitskosten') %]</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                        <input type="text" id="SearchValue" class="form-control hideForWages" placeholder="[% $user->gettext('Rechnungs- oder Artikelnr.') %]"/>
                                    </div>
                                    <div class="col-sm-3">
                                        <input type="button" class="btn btn-outline-secondary hideForWages" value="[% $user->gettext('Artikel abrufen') %]" onclick="GetInvoices();" />
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-2 ">                        
                                <span class="btn btn-outline-secondary pull-right" id="takeoverSelection">[% $user->gettext('Auswahl übernehmen') %]</span>                        
                            </div>
                        </div>
                    </div>
                    <div class="card-body">

                        <div class="row">
                            <div class="col-md-12">
                                <h4>[% $user->gettext('Positionen wählen') %]</h4>
                            </div>
                        

                            <div class="col-md-12" id="InvoicePositionList" style="max-height:40vh;overflow-y:scroll"></div>

                            <div class="col-md-12">
                                <h4>[% $user->gettext('Gewählte Positionen') %]</h4>
                            </div>
                            <div class="col-md-12" id="PositionSelectionPanel" style="overflow-y:scroll">

                                <table class="table table-striped table-hover" id="WarrantyProcessingInvoicePositionTable" >
                                    <thead>
                                        <tr>
                                            <th>[% $user->gettext('ET-NR.') %]</th>
                                            <th>[% $user->gettext('Beschreibung') %]</th>
                                            <th>[% $user->gettext('Anzahl') %]</th>
                                            <th>[% $user->gettext('Einzelpreis') %]</th>
                                            <th>[% $user->gettext('Gesamtpreis') %]</th>
                                            <th>[% $user->gettext('Fracht') %]</th>
                                            <th>[% $user->gettext('Rechnungsnr.') %]</th>
                                            <th>[% $user->gettext('Klassifikation') %]</th>
                                            <th>[% $user->gettext('Fehlerbild') %]</th>

                                            <th>[% $user->gettext('Seriennummern') %]</th>
                                            <th>[% $user->gettext('Kundenbez.') %]</th>                                            
                                            <th>[% $user->gettext('Aktionen') %]</th>
                                        </tr>
                                    </thead>
                                    <tbody id='PositionSelection'>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>


    $('#takeoverSelection').on('click', function () {

        var currentTid = 0;
        if (typeof (tid) !== 'undefined') {
            var currentTid = tid;
        }





        $("#SavedPositionList").load("index.php?module=ticket&event=selectedPositions", { selectedPositions: addedPositionObjects, TicketID: currentTid });
        //addedPositionObjects = {};
        $('#PositionSelection').html('');
        addedArtikel = [];
        if (currentTid > 0) {
            addedPositionObjects = {}; //Wird die Liste nicht geleert, werden nach einer erneuten Auswahl Artikel nochmals zugefügt.
        }

        

        $('#PositionsSource').val("rdbSearchInvoice").trigger('change'); //Initial wird nach Rechnungen gesucht.
        $('#PositionSelectionModal').modal('toggle');
    })

    $('#PositionsSource').on('change', function (e) {
        if($(this).val() == 'SelectWagePositions'){
            $("#InvoicePositionList").html('<div class="col-sm-6 offset-6"><i class="fas fa-spinner fa-spin fs-3"></i></div>');
            $('#InvoicePositionList').load('index.php?module=wprequest&event=getWagePositions', {DealerID: $('#paKDNR').val()});
            $('.hideForWages').hide();
        } else {
            $('#InvoicePositionList').html('');
            $('.hideForWages').show();
        }
    })

            function DeletePositionFromSelection(ETNumber, WarrantyProcessingRequestPositionID, pAPositionsNr) {                  
                $('#TableRowForPosition_' + ETNumber).remove(); //Tabelleneintrag entfernen
                $("[id^='PositionFormData_" + ETNumber + "_']").remove(); //Formularfelder mit den Artikeldaten entfernen 
                //Eintrag aus Array entfernen:
                indexNo = addedArtikel.indexOf(ETNumber);
                if (indexNo > -1) {
                    addedArtikel.splice(indexNo, 1);
                }
                delete addedPositionObjects[ETNumber];
                //Dropzone entfernen:
                try {
                    Dropzone.forElement("#WPPositionDropzoneField_" + ETNumber).destroy();
                } catch (error) {
                            
                } 
            }

</script>
