
<script type="text/javascript">

    function switchPage(pos) {
        document.getElementById("pos").value = pos;
        submitForm();
    }

</script>

<style>
    .table th{
        cursor: pointer;
    }
</style>
<form action="index.php?module=assets&class=commercialdevdata" method="post" name="hm" onsubmit="" id="hm" enctype="multipart/form-data" class=" form-inline" >

    <input type="hidden" id="sort" name="sort" value="[% $sort %]" />
    <input type="hidden" id="sortorder" name="sortorder" value="[% $sortorder %]" />
    <input type="hidden" id="message" name="message" value="0" />
    <input type="hidden" id="type" name="type" value="" />
    <input type="hidden" name="pos" value="[% $pos %]" id="pos">
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <span class="fcs-card-title h2">[% $user->gettext('Kommerzielle Gerätedaten') %]</span>
        </div>
        <div class="card-body">
            [% if !$GetForDevice %]
            <div class="card panel-info shadow-sm rounded">
                <div class="card-body">
                    <div class="fcs-form-padding">
                        <div class="form-group row mb-3">
                            <label class="control-label">
                                [% $user->gettext('Eintr&auml;ge pro Seite') %]
                            </label>
                            <select name="entries_per_page" onchange="document.hm.submit();" class="form-control">                                                
                                <option value="10" [% if $entries_per_page == 10 %]selected="selected"[% /if %]>10</option>
                                <option value="20" [% if $entries_per_page == 20 %]selected="selected"[% /if %]>20</option>
                                <option value="50" [% if $entries_per_page == 50 %]selected="selected"[% /if %]>50</option>
                                <option value="100" [% if $entries_per_page == 100 %]selected="selected"[% /if %]>100</option>
                            </select>&nbsp;&nbsp;&nbsp;
                        </div>
                            
                        <div class="form-group row mb-3">
                            <label class="control-label">
                                [% $user->gettext('Gerätename') %]
                            </label>
                            <input type="text" class="form-control Filter" value="[% if $Filter.devicename %][% $Filter.devicename %][% /if %]" id="FilterDeviceName" name="Filter[devicename]">
                        </div>
                        
                        <div class="form-group row mb-3">
                            <label class="control-label">
                                [% $user->gettext('Hostname') %]
                            </label>
                            <input type="text" class="form-control Filter" value="[% if $Filter.hostname %][% $Filter.hostname %][% /if %]" id="FilterHostName" name="Filter[hostname]">
                        </div>
                        
                        <div class="btn-group">
                            <button class="btn btn-outline-secondary"><span class="fa fa-search"></span></button>
                            <a class="btn btn-outline-secondary" onclick="clearInput();"><span class="fa fa-arrows-rotate"></span></a>
                        </div>
                    </div>
                </div>
                [% /if %]
            </div>

            <div class="card panel-info shadow-sm rounded">
                <div class="card-header">
                    <div class="row">
                        <div class="col-sm-9">
                             <span class="fcs-card-title h3">
                            [% $entries %]
                            [% if $entries > 1 %]
                                [% $user->gettext('Eintrag') %]
                            [% else %]
                                [% $user->gettext('Einträge') %]
                            [% /if %]
                            [% $user->gettext('gefunden') %]
                        </span>
                        </div>
                        <div class="col-sm-3 text-end">
                            [% if !$GetForDevice %]
                            <a  class="btn btn-outline-primary" type="button" href="index.php?module=assets">
                                [%$user->gettext('Assets')%]
                            </a>
                            <a  class="btn btn-outline-primary" type="button" href="index.php?module=assets&class=commercialdevdata&event=CSVImport">
                                [%$user->gettext('CSV Import')%]
                            </a>
                            <a  class="btn btn-outline-primary" type="button" href="index.php?module=assets&class=commercialdevdata&export=csv">
                                [%$user->gettext('CSV Export')%]
                            </a>
                            <a href="index.php?module=assets&class=commercialdevdata&event=saveData" class="btn btn-outline-primary">
                                [% $user->gettext('Neue kommerzielle Daten') %]
                            </a>
                            [% /if %]
                        </div>
                    </div>
                   
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered  table-condensed">
                            <thead>
                                <tr class="fields>">
                                    <th class="sort" id="commercialdevdataid">[% $user->gettext('ID') %]</th>
                                    <th class="sort" id="devicename">[% $user->gettext('Gerätename') %]</th>
                                    <th class="sort" id="hostname">[% $user->gettext('Hostname') %]</th>
                                    <th class="sort" id="leasingvendornameshort">[% $user->gettext('leasingvendornameshort') %]</th>
                                    <th class="sort" id="leasingvendorname1">[% $user->gettext('leasingvendorname1') %]</th>
                                     <th class="sort" id="vendornameshort">[% $user->gettext('vendornameshort') %]</th>
                                    <th class="sort" id="vendorname1">[% $user->gettext('vendorname1') %]</th>
                                    <th class="sort" id="inventoryno">[% $user->gettext('inventoryno') %]</th>
                                    <th class="sort" id="assetno">[% $user->gettext('assetno') %]</th>
                                    <th class="sort" id="purchasedate">[% $user->gettext('purchasedate') %]</th>
                                    <th class="sort" id="deliverydate">[% $user->gettext('deliverydate') %]</th>
                                    <th class="sort" id="purchaseprice">[% $user->gettext('purchaseprice') %]</th>
                                    <th class="sort" id="description">[% $user->gettext('description') %]</th>
                                    <th class="sort" id="outdate">[% $user->gettext('outdate') %]</th>
                                    <th class="sort" id="manupartnumber">[% $user->gettext('manupartnumber') %]</th>
                                    <th class="sort" id="leasingactiv">[% $user->gettext('leasingactiv') %]</th>
                                    <th class="sort" id="leasingperiod">[% $user->gettext('leasingperiod') %]</th>
                                    <th class="sort" id="leasingrate">[% $user->gettext('leasingrate') %]</th>
                                    <th class="sort" id="leasingstartdate">[% $user->gettext('leasingstartdate') %]</th>
                                    <th class="sort" id="leasingenddate">[% $user->gettext('leasingenddate') %]</th>
                                    <th class="sort" id="leasingfactor">[% $user->gettext('leasingfactor') %]</th>
                                    <th class="sort" id="leasingbasicprice">[% $user->gettext('leasingbasicprice') %]</th>
                                    <th class="sort" id="leasingremainvalue">[% $user->gettext('leasingremainvalue') %]</th>
                                    <th class="sort" id="leasingaccount">[% $user->gettext('leasingaccount') %]</th>
                                    <th class="sort" id="warrantyend">[% $user->gettext('warrantyend') %]</th>
                                    <th class="sort" id="afaactiv">[% $user->gettext('afaactiv') %]</th>
                                    <th class="sort" id="afabasicprice">[% $user->gettext('afabasicprice') %]</th>
                                    <th class="sort" id="afausingperiod">[% $user->gettext('afausingperiod') %]</th>
                                    <th class="sort" id="afaaccount">[% $user->gettext('afaaccount') %]</th>
                                    <th class="sort" id="afastartdate">[% $user->gettext('afastartdate') %]</th>
                                    <th class="sort" id="afaenddate">[% $user->gettext('afaenddate') %]</th>
                                    <th class="sort" id="contactpersontitle">[% $user->gettext('contactpersontitle') %]</th>
                                    <th class="sort" id="contactpersonname">[% $user->gettext('contactpersonname') %]</th>
                                    <th class="sort" id="contactpersonphone">[% $user->gettext('contactpersonphone') %]</th>
                                    <th class="sort" id="deliverynote">[% $user->gettext('deliverynote') %]</th>
                                    
                                    [% if !$GetForDevice %]
                                    <th></th>
                                    [% /if %]
                                </tr>
                            </thead>
                            <tbody>
                                [% foreach from=$CDData item=data key=id %]

                                    <tr>
                                        <td>[% $id %]</td>
                                        <td>[% $data.devicename %]</td>
                                        <td>[% $data.hostname %]</td>
                                        <td>[% $data.leasingvendornameshort  %]</td>
                                        <td>[% $data.leasingvendorname1 %]</td>
                                        <td>[% $data.vendornameshort %]</td>
                                        <td>[% $data.vendorname1 %]</td>
                                        <td>[% $data.inventoryno  %]</td>
                                        <td>[% $data.assetno %]</td>
                                        <td>[% if $data.purchasedate %][% $data.purchasedate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% if $data.deliverydate %][% $data.deliverydate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% if  $data.purchaseprice%][% $data.purchaseprice|string_format:"%.2f" %][% /if %]</td>
                                        <td>[% $data.description %]</td>
                                        <td>[% if $data.outdate %][% $data.outdate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% $data.manupartnumber %]</td>
                                        <td>[% if $data.leasingactiv %]<span class="fa fa-check"></span>[% /if %]</td>
                                        <td>[% $data.leasingperiod %]</td>
                                        <td>[% $data.leasingrate %]</td>
                                        <td>[% if $data.leasingstartdate %][% $data.leasingstartdate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% if $data.leasingenddate %][% $data.leasingenddate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% $data.leasingfactor %]</td>
                                        <td>[% if $data.leasingbasicprice %][% $data.leasingbasicprice|string_format:"%.2f" %][% /if %]</td>
                                        <td>[% $data.leasingremainvalue %]</td>
                                        <td>[% $data.leasingaccount %]</td>
                                        <td>[% if $data.warrantyend %][% $data.warrantyend|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% if $data.afaactiv %]<span class="fa fa-check"></span>[% /if %]</td>
                                        <td>[% if $data.afabasicprice %][% $data.afabasicprice|string_format:"%.2f" %][% /if %]</td>
                                        <td>[% $data.afausingperiod %]</td>
                                        <td>[% $data.afaaccount %]</td>
                                        <td>[% if $data.afastartdate %][% $data.afastartdate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% if $data.afaenddate %][% $data.afaenddate|date_format:"%d.%m.%Y %H:%M" %][% /if %]</td>
                                        <td>[% $data.contactpersontitle %]</td>
                                        <td>[% $data.contactpersonname %]</td>
                                        <td>[% $data.contactpersonphone %]</td>
                                        <td>[% $data.deliverynote %]</td>
                                        [% if !$GetForDevice %]
                                        <td style="text-align:center !important;">
                                            <a href="index.php?module=assets&class=commercialdevdata&event=saveData&commercialdevdataid=[% $id %]" class="btn btn-outline-secondary"><span class="fa fa-pencil" title="[% $user->gettext('Bearbeiten') %]"></span></a>
                                            <a href="javascript:deleteField([% $field.field_id %])" class="btn btn-outline-secondary"><span class="fa fa-trash" title="[% $user->gettext('Löschen') %]"></span></a>
                                        </td>
                                        [% /if %]
                                    </tr>
                                [% foreachelse %]
                                    <tr class="even">
                                        <td colspan="9" style="text-align:center !important">[% $user->gettext('Es wurden keine Felder gefunden...') %]</td>
                                    </tr>
                                [% /foreach %]
                            </tbody>
                        </table>

                    </div>
                    <div class="col-lg-12 col-sm-12 hidden-sm hidden-xs">
                        <div class="col-lg-6 col-sm-6"></div>
                        <div class="col-lg-6 col-sm-6 text-end">
                            [% $Paging %]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $('.select2').select2({theme: 'bootstrap-5'});
</script>
<div class="modal fade" id="removeModal" tabindex="-1" role="dialog" aria-labelledby="removeModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body modalContent">
                ...
            </div>
        </div>
    </div>
</div>

<script>
    var current_sort = $("#sort").val();
    var current_sortorder = $("#sortorder").val();
    showSortIcon();
    $(".sort").on("click", function (e) {
        var sort = $(this).attr('id');
        var sortorder = 'asc';
        if (current_sort === sort) {
            if (current_sortorder === 'asc') {
                sortorder = 'desc';
            } else {
                sortorder = 'asc';
            }
        }
        $("#sort").val(sort);
        $("#sortorder").val(sortorder);
        submitForm();
    })

    function showSortIcon() {
        var content = $("#" + current_sort).html();
        if (current_sortorder == 'desc') {
            content += '<span class="fa fa-chevron-down"></span>';

        } else {
            content += '<span class="fa fa-chevron-up"></span>';
        }
        $("#" + current_sort).html(content);
    }
    
    /**
 * 
 */
function clearInput() {
    $(".Filter").val("");
    document.hm.submit();
}

</script>
