<!doctype html>
<?php

use Jackiedo\DotenvEditor\Facades\DotenvEditor;


$MAIL_HOST = DotenvEditor::load(base_path('.env'))->getValue('MAIL_HOST');
$editor = DotenvEditor::load(storage_path('app/settings.env'));


?>
<html lang="en" class="h-100">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Rechnungswesen - {{$editor->getKey('APP_TITLE')['value']}}</title>
    <link rel="icon" type="image/vnd.microsoft.icon" href="/images/bürozeit.ico">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@7.4.47/css/materialdesignicons.min.css">

    <!-- JQuery -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>

    <!-- Latest compiled and minified CSS -->
    <!--link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.21.1/dist/bootstrap-table.min.css"-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.21.1/dist/bootstrap-table.min.css">

    <!-- Latest compiled and minified JavaScript -->
    <!--script src="https://unpkg.com/bootstrap-table@1.21.1/dist/bootstrap-table.min.js"></script-->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.21.1/dist/bootstrap-table.min.js"></script>
    <!-- Latest compiled and minified Locales -->
    <!--script src="https://unpkg.com/bootstrap-table@1.21.1/dist/locale/bootstrap-table-de-DE.min.js"></script-->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.21.1/dist/locale/bootstrap-table-de-DE.js"></script>


    <!--link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.21.1/dist/extensions/reorder-rows/bootstrap-table-reorder-rows.css"-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-table@1.21.1/dist/extensions/reorder-rows/bootstrap-table-reorder-rows.css">
    <!--script src="https://cdnjs.cloudflare.com/ajax/libs/TableDnD/1.0.5/jquery.tablednd.js"></script -->
    <script src="https://cdn.jsdelivr.net/gh/isocra/TableDnD@1.0.5/dist/jquery.tablednd.1.0.5.js"></script>
    <!--script src="https://unpkg.com/bootstrap-table@1.21.1/dist/extensions/reorder-rows/bootstrap-table-reorder-rows.js"></script-->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-table@1.21.1/dist/extensions/reorder-rows/bootstrap-table-reorder-rows.js"></script>

    <!-- Bootstrap -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>

    <!-- Bootstrap editable -->
    <link rel="stylesheet" href="{{url('/css/xeditable.css')}}">
     <script src="{{url('/js/bootstrap.editable.js')}}"></script>
    <script src="{{url('/js/x-editable.js')}}"></script>
    <script src="{{url('/js/bootstrap-table.editable.js')}}"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.0.0/moment.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

    <link rel="stylesheet" href="{{url('/css/bootstrap/bootstrap.dialogs.css')}}">
    <script src="{{url('/js/bootstrap.dialogs.js')}}"></script>

    <!-- Tabulator -->

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tabulator-tables@5.4.3/dist/css/tabulator.min.css">
    <script src="https://cdn.jsdelivr.net/npm/tabulator-tables@5.4.3/dist/js/tabulator.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tabulator-tables@5.4.3/dist/css/tabulator_bootstrap5.min.css">



    <script src="https://cdn.jsdelivr.net/npm/luxon@3.2.1/build/global/luxon.min.js"></script>


    <script src="{{url('js/hwplus.js?1')}}"></script>
    <link rel="stylesheet" href="{{url('css/hwplus.css')}}">

    <style>

        .btn-warning { background-color: var(--orange)!important; border-color: var(--orange)!important; color:white;  }

    </style>

    <script>



   var netCalc = function(values, data, calcParams) {
        //values - array of column values
        //data - all table data
        //calcParams - params passed from the column definition object

        var calc = 0;

        values.forEach(function(value){
            value = parseFloat(value.replace(',','.'));
            calc = calc + value;
        });

        return calc.toFixed(2) + '€';
    }

    var sumCalc = function(values, data, calcParams) {
        //values - array of column values
        //data - all table data
        //calcParams - params passed from the column definition object

        var calc = 0;

        values.forEach(function(value){
            value = parseFloat(value);
            calc = calc + value;
        });

        return calc.toFixed(2) + '€';
    }

   var editCheck = function(cell){
        return {{$model->invoice_number ? "false" : "true"}}
    }


    $(function() {



        setInterval(function() {

            let mwst = 0;
            let brutto = 0;
            let gesamt = 0;
            let sum = $('div.tabulator-footer [tabulator-field="sum"]');
            $(sum).each(function() {
                let s = $(this).html();
                    s = s.slice(0, -1);
                    s = parseFloat(s);
                gesamt += s;

            });

            mwst = gesamt / 100 * 19;
            brutto = gesamt + mwst;
            $('.netto_gesamt').html('Gesamt netto: ' + gesamt.toFixed(2) + '€');
            $('.brutto').html('Gesamt brutto (inkl. 19% MwSt.): ' + (brutto.toFixed(2)) + '€');

            }, 2000);

        @php
        $data = \App\Models\PHPXPress\HwplusInvoiceItems::with('_meta._doctype')->whereHas('_meta._doctype', function($query) {
            $query->where('ID', '050b070c151f8f0b9d76589922f58a908e67535f');
        })->where('_items_at_hwplus_invoices', $model->getKey())->get();
        @endphp

        let fareTableData = @json($data);

        fareTable = new Tabulator("#fareTable", {
            movableRows:editCheck(),
            layout:"fitColumns",
            selectable: editCheck(),
            rowHeight:100,
            data:fareTableData,
            index: "ID",
            initialSort:[{column:'sort_order', dir:'asc'}],
            columns:[ //set column definitions for imported table data
                {title:"ID", field:'ID', visible:false, sorter:"number"},
                {formatter:"rowSelection", headerSort:false, width:10},
                {rowHandle:true, formatter:"handle", headerSort:false, width:10, vertAlign:'top'},
                {title:"", field:'sort_order', visible:true, sorter:'number', width:10},
                {title:"Bezeichnung", field:'descriptor', visible:true, sorter:'string', editor:"textarea", editable:editCheck, formatter:"textarea", editorParams:             {
                    selectContents:true,
                }},
                {title:'Menge', field:'amount', visible:true, width:100, editor:'input', mutateLink:"brutto", editable:editCheck, mutateLink:"sum", editorParams:             {
                    selectContents:true
                }},
                {title:'Einzelpreis', field:'netprice', visible:true, width:150, editor:'input', editable:editCheck, bottomCalc:netCalc, formatter: function(cell) { return cell.getValue() + '€'}, mutateLink:"sum", editorParams:             {
                    selectContents:true,
                }},
                {title:'MwSt.', field:'vat', visible:true, width:100, editor:'input', editable:editCheck, formatter: function(cell) { return cell.getValue() + '%'}, editorParams:             {
                    selectContents:true,
                }},
                {title:'Gesamt', field:'sum', visible:true, width:150, bottomCalc:sumCalc, mutator: function(value, row) { return parseFloat(row.netprice.replace(',','.')) * parseFloat(row.amount.replace(',','.')); }, formatter: function(cell) { return cell.getValue().toFixed(2) + '€'}},
            ],
        });

        fareTable.on("rowSelected", function(row){
            $('#fare_menu_button').prop("disabled",false);
        });

        fareTable.on("rowDeselected", function(row){
            $('#fare_menu_button').prop("disabled",true);
        });

        fareTable.on("rowMoved", function(row) {

        return;

                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                postData.data['_material_at_tickets_order'] = row.getPosition();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/c5b93c44c6aa831b9f9b39580a9efeed7470c8bc/" + row.getData().ID, postData)

                    .done(function(data) {

                        invoiceTable.setData("../../../api/{{$repository->getConfig()->_service->url}}/afe4f16263308b092d15e04719f202efe1326813/{{$model->getKey()}}/_material");

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr) {

                        $('#spinner').addClass('d-none');

                        alertException(xhr);
                    });


        });


        fareTable.on("cellEdited", function(cell){


                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                let row = cell.getRow().getData();

                postData.data[cell.getField()] = cell.getValue();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + row.ID, postData)

                    .done(function() {

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr, status, error) {

                        $('#spinner').addClass('d-none');
                        cell.restoreOldValue();

                        alertException(xhr);



                    });
        });

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


            BootstrapDialog.show({
                message: $('<div></div>').load('../../create/8d9c8b3182023463c3470b19e7b4dad2511868cc/050b070c151f8f0b9d76589922f58a908e67535f?data[_items_at_hwplus_invoices]={{$model->getKey()}}'),
                title:'Rechnungsposition erfassen',
                type:BootstrapDialog.TYPE_LIGHT,
                buttons: [{
                    label: 'Speichern',
                    cssClass:'btn-success',
                    action: function(dialogItself) {

                        $('#spinner').removeClass('d-none');

                        let postData = $('#new_invoice_item').serialize();

                        $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/050b070c151f8f0b9d76589922f58a908e67535f", postData)

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            fareTable.addData(data);
                            dialogItself.close();

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            if(422 == xhr.status) {

                                    $('#new_invoice_item').find('.is-invalid').removeClass('is-invalid');
                                    $.each(xhr.responseJSON, function(index, item) {
                                        let array = index.split('.');
                                        $('#new_invoice_item').find('[name="data['+array[1]+']"]').addClass('is-invalid');
                                    });

                                    return;

                            }

                            alertException(xhr);


                        });

                    }
                }, {
                    label: 'Abbrechen',
                    action: function(dialogItself){
                        dialogItself.close();
                    }
                }]
            });

        })




        $('#drop_fare_button').click(function() {

            BootstrapDialog.confirm('Rechnungsposition löschen bestätigen?', function(result){
                if(result) {

                    $('#spinner').removeClass('d-none');

                    let postData = {
                        _token:'{{csrf_token()}}',
                        _method: 'DELETE',
                    }

                    let selectedRowID = fareTable.getSelectedData()[0].ID;

                    $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + selectedRowID, postData)

                        .done(function() {

                            $('#spinner').addClass('d-none');

                            fareTable.deleteRow(selectedRowID);

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);
                        });
                    $('#fare_menu_button').prop('disabled', true);
                }
            });


        })



        invoiceTextTable = new Tabulator("#invoiceTextTable", {
            movableRows:true,
            layout:"fitColumns",
            selectable: 1,
            rowHeight:100,
            data:@json(\App\Models\PHPXPress\HwplusInvoiceNotes::where('_notes_at_hwplus_invoices', $model->getKey())->get()),
            initialSort:[{column:'sort', dir:'asc'}],
            columns:[ //set column definitions for imported table data
                {title:"ID", field:'ID', visible:false, sorter:"number"},
                {formatter:"rowSelection", headerSort:false, width:10},
                {rowHandle:true, formatter:"handle", headerSort:false, width:10, vertAlign:'top'},
                {title:"", field:'sort', visible:true, sorter:'number', width:10},
                {title:'Text', field:'text', visible:true, editor:'textarea', formatter:"textarea" },
            ],
        });




        invoiceTextTable.on("rowSelected", function(row){
            $('#invoice_text_menu_button').prop("disabled",false);
        });

        invoiceTextTable.on("rowDeselected", function(row){
            $('#invoice_text_menu_button').prop("disabled",true);
        });

        invoiceTextTable.on("rowMoved", function(row) {

                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                postData.data['_notes_at_hwplus_invoices_order'] = row.getPosition();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/89157a15b3ce224a6dbcffe3e2d3461e319319a6/" + row.getData().ID, postData)

                    .done(function(data) {

                        invoiceTextTable.setData("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}/_notes");

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr) {

                        $('#spinner').addClass('d-none');

                        alertException(xhr);
                    });


        });


        invoiceTextTable.on("cellEdited", function(cell){

                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                let row = cell.getRow().getData();

                postData.data[cell.getField()] = cell.getValue();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/89157a15b3ce224a6dbcffe3e2d3461e319319a6/" + row.ID, postData)

                    .done(function() {

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr, status, error) {

                        $('#spinner').addClass('d-none');
                        cell.restoreOldValue();

                        alertException(xhr);



                    });
        });

        $('#drop_invoice_text_button').click(function() {


            dialog = BootstrapDialog.confirm('Rechnungstext löschen bestätigen?', function(result){
                if(result) {

                    $('#spinner').removeClass('d-none');

                    let postData = {
                        _token:'{{csrf_token()}}',
                        _method: 'DELETE',
                    }

                    let selectedRowID = invoiceTextTable.getSelectedData()[0].ID;

                    $.post("../../../api/{{$repository->getConfig()->_service->url}}/89157a15b3ce224a6dbcffe3e2d3461e319319a6/" + selectedRowID, postData)

                        .done(function() {

                            $('#spinner').addClass('d-none');

                            invoiceTextTable.getSelectedRows()[0].delete();

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);
                        });

                    $('#manhour_menu_button').prop('disabled', true);
                }
            });


        })

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


            dialog = BootstrapDialog.show({
                message: $('<div></div>').load('../../9ae4379e916a6a802c876f27dd76d988d43df31b/84b692d8b9ce096bca28327be5fe9ac581bba7a2?data[_notes_at_hwplus_invoices]={{$model->getKey()}}'),
                title:'Rechnungstext hinzufügen',
            });

        })









        @php
        $data = \App\Models\PHPXPress\HwplusInvoiceItems::with('_meta._doctype')->whereHas('_meta._doctype', function($query) {
            $query->where('ID', 'cba3def15e0e6c1151fe202c8b00c2a0c1951909');
        })->where('_items_at_hwplus_invoices', $model->getKey())->get();
        @endphp

        let aeTableData = @json($data);

        aeTable = new Tabulator("#aeTable", {
            movableRows:editCheck(),
            layout:"fitColumns",
            selectable: editCheck(),
            data:aeTableData,
            index: "ID",
            initialSort:[{column:'sort_order', dir:'asc'}],
            columns:[ //set column definitions for imported table data
                {title:"ID", field:'ID', visible:false, sorter:"number"},
                {formatter:"rowSelection", headerSort:false, width:10},
                {rowHandle:true, formatter:"handle", headerSort:false, width:10, vertAlign:"top"},
                {title:"", field:'sort_order', visible:true, sorter:'number', width:10},
                {title:"Bezeichnung", field:'descriptor', visible:true, sorter:'string', editor:"textarea", editable:editCheck, formatter:"textarea", editorParams:             {
                    selectContents:true,
                }
                },
                {title:'Menge', field:'amount', visible:true, width:100,  editor:'input', editable:editCheck, mutateLink:"sum", editorParams:             {
                    selectContents:true,
                }},
                {title:'Einzelpreis', field:'netprice', visible:true, width:150,  editor:'input', editable:editCheck, bottomCalc:netCalc, formatter: function(cell) { return cell.getValue() + '€'}, mutateLink:"sum", editorParams:             {
                    selectContents:true,
                }},
                {title:'MwSt.', field:'vat', visible:true, width:100, editor:'input', editable:editCheck, formatter: function(cell) { return cell.getValue() + '%'}, editorParams:             {
                    selectContents:true,
                }},
                {title:'Gesamt', field:'sum', visible:true, width:150, bottomCalc:sumCalc, mutator: function(value, row) { return parseFloat(row.netprice.replace(',','.')) * parseFloat(row.amount.replace(',','.')); }, formatter: function(cell) { return cell.getValue().toFixed(2) + '€'}},

            ],
        });


        aeTable.on("rowSelected", function(row){
            $('#ae_menu_button').prop("disabled",false);
        });

        aeTable.on("rowDeselected", function(row){
            $('#ae_menu_button').prop("disabled",true);
        });

        aeTable.on("rowMoved", function(row) {

        return;

                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                postData.data['_material_at_tickets_order'] = row.getPosition();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/c5b93c44c6aa831b9f9b39580a9efeed7470c8bc/" + row.getData().ID, postData)

                    .done(function(data) {

                        invoiceTable.setData("../../../api/{{$repository->getConfig()->_service->url}}/afe4f16263308b092d15e04719f202efe1326813/{{$model->getKey()}}/_material");

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr) {

                        $('#spinner').addClass('d-none');

                        alertException(xhr);
                    });


        });

        aeTable.on("cellEdited", function(cell){


                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                let row = cell.getRow().getData();

                postData.data[cell.getField()] = cell.getValue();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + row.ID, postData)

                    .done(function() {

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr, status, error) {

                        $('#spinner').addClass('d-none');
                        cell.restoreOldValue();

                        alertException(xhr);



                    });
        });

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

            BootstrapDialog.show({
                message: $('<div></div>').load('../../create/8d9c8b3182023463c3470b19e7b4dad2511868cc/cba3def15e0e6c1151fe202c8b00c2a0c1951909?data[_items_at_hwplus_invoices]={{$model->getKey()}}'),
                title:'Rechnungsposition erfassen',
                type:BootstrapDialog.TYPE_LIGHT,
                buttons: [{
                    label: 'Speichern',
                    cssClass:'btn-success',
                    action: function(dialogItself) {

                        $('#spinner').removeClass('d-none');

                        let postData = $('#new_invoice_item').serialize();

                        $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/cba3def15e0e6c1151fe202c8b00c2a0c1951909", postData)

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            aeTable.addData(data);
                            dialogItself.close();

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            if(422 == xhr.status) {

                                    $('#new_invoice_item').find('.is-invalid').removeClass('is-invalid');
                                    $.each(xhr.responseJSON, function(index, item) {
                                        let array = index.split('.');
                                        $('#new_invoice_item').find('[name="data['+array[1]+']"]').addClass('is-invalid');
                                    });

                                    return;

                            }

                            alertException(xhr);


                        });

                    }
                }, {
                    label: 'Abbrechen',
                    action: function(dialogItself){
                        dialogItself.close();
                    }
                }]
            });

        })




        $('#drop_ae_button').click(function() {

            BootstrapDialog.confirm('Rechnungsposition löschen bestätigen?', function(result){
                if(result) {

                    $('#spinner').removeClass('d-none');

                    let postData = {
                        _token:'{{csrf_token()}}',
                        _method: 'DELETE',
                    }

                    let selectedRowID = aeTable.getSelectedData()[0].ID;

                    $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + selectedRowID, postData)

                        .done(function() {

                            $('#spinner').addClass('d-none');

                            aeTable.deleteRow(selectedRowID);



                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);
                        });
                    $('#ae_menu_button').prop('disabled', true);
                }
            });


        })











        @php
        $data = \App\Models\PHPXPress\HwplusInvoiceItems::with('_meta._doctype')->whereHas('_meta._doctype', function($query) {
            $query->where('ID', '854cbb63e8c1319f02330c2e61e7b93bf4682cc2');
        })->where('_items_at_hwplus_invoices', $model->getKey())->get();
        @endphp
        let invoiceTableData = @json($data)

        invoiceTable = new Tabulator("#invoiceTable", {
            movableRows:editCheck(),
            layout:"fitColumns",
            selectable: editCheck(),
            rowHeight:100,
            data:invoiceTableData,
            index: "ID",
            initialSort:[{column:'sort_order', dir:'asc'}],
            columns:[ //set column definitions for imported table data
                {title:"ID", field:'ID', visible:false, sorter:"number"},
                {formatter:"rowSelection", headerSort:false, width:60},
                {rowHandle:true, formatter:"handle", headerSort:false, width:10, vertAlign:'top'},
                {title:"", field:'sort_order', visible:true, sorter:'number', width:10},
                {title:"Bezeichnung", field:'descriptor', visible:true, sorter:'string', editor:"textarea", editable:editCheck, formatter:"textarea", editorParams:             {
                    selectContents:true,
                }},
                {title:'VPE', field:'unit', visible:true, __editor:'input', width:100, editable:editCheck , editorParams:             {
                    selectContents:true,
                }},
                {title:'Menge', field:'amount', visible:true, editor:'input', width:100, mutateLink:"brutto", editable:editCheck, mutateLink:"sum", editorParams:             {
                    selectContents:true,
                }},
                {title:'Einzelpreis', field:'netprice', visible:true, editor:'input', width:150, editable:editCheck, bottomCalc:netCalc, formatter: function(cell) { return cell.getValue() + '€'}, mutateLink:"sum", editorParams:             {
                    selectContents:true,
                }},
                {title:'MwSt.', field:'vat', visible:true, editor:'input', width:100, editable:editCheck, formatter: function(cell) { return cell.getValue() + '%'}, editorParams:             {
                    selectContents:true,
                }},
                {title:'Gesamt', field:'sum', visible:true, bottomCalc:sumCalc, width:150, mutator: function(value, row) { return parseFloat(row.netprice.replace(',','.')) * parseFloat(row.amount.replace(',','.')); }, formatter: function(cell) { return cell.getValue().toFixed(2) + '€'}},
            ],
        });


        invoiceTable.on("rowSelected", function(row){
            $('#material_menu_button').prop("disabled",false);
        });

        invoiceTable.on("rowDeselected", function(row){
            $('#material_menu_button').prop("disabled",true);
        });

        invoiceTable.on("rowMoved", function(row) {

        return;

                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                postData.data['_material_at_tickets_order'] = row.getPosition();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/c5b93c44c6aa831b9f9b39580a9efeed7470c8bc/" + row.getData().ID, postData)

                    .done(function(data) {

                        invoiceTable.setData("../../../api/{{$repository->getConfig()->_service->url}}/afe4f16263308b092d15e04719f202efe1326813/{{$model->getKey()}}/_material");

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr) {

                        $('#spinner').addClass('d-none');

                        alertException(xhr);
                    });


        });


        invoiceTable.on("cellEdited", function(cell){


                $('#spinner').removeClass('d-none');

                let postData = {
                    _token:'{{csrf_token()}}',
                    _method: 'PUT',
                    data: {}
                }

                let row = cell.getRow().getData();

                postData.data[cell.getField()] = cell.getValue();

                $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + row.ID, postData)

                    .done(function() {

                        $('#spinner').addClass('d-none');

                    })

                    .fail(function(xhr, status, error) {

                        $('#spinner').addClass('d-none');
                        cell.restoreOldValue();

                        alertException(xhr);



                    });
        });

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

            BootstrapDialog.show({
                message: $('<div></div>').load('../../create/8d9c8b3182023463c3470b19e7b4dad2511868cc/854cbb63e8c1319f02330c2e61e7b93bf4682cc2?data[_items_at_hwplus_invoices]={{$model->getKey()}}'),
                title:'Rechnungsposition erfassen',
                type:BootstrapDialog.TYPE_LIGHT,
                buttons: [{
                    label: 'Speichern',
                    cssClass:'btn-success',
                    action: function(dialogItself) {

                        $('#spinner').removeClass('d-none');

                        let postData = $('#new_invoice_item').serialize();

                        $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/854cbb63e8c1319f02330c2e61e7b93bf4682cc2", postData)

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            invoiceTable.addData(data);
                            dialogItself.close();

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            if(422 == xhr.status) {

                                    $('#new_invoice_item').find('.is-invalid').removeClass('is-invalid');
                                    $.each(xhr.responseJSON, function(index, item) {
                                        let array = index.split('.');
                                        $('#new_invoice_item').find('[name="data['+array[1]+']"]').addClass('is-invalid');
                                    });

                                    return;

                            }

                            alertException(xhr);


                        });

                    }
                }, {
                    label: 'Abbrechen',
                    action: function(dialogItself){
                        dialogItself.close();
                    }
                }]
            });

        })




        $('#drop_material_button').click(function() {

            BootstrapDialog.confirm('Rechnungsposition löschen bestätigen?', function(result){
                if(result) {

                    $('#spinner').removeClass('d-none');

                    let postData = {
                        _token:'{{csrf_token()}}',
                        _method: 'DELETE',
                    }

                    let selectedRowID = invoiceTable.getSelectedData()[0].ID;

                    $.post("../../../api/{{$repository->getConfig()->_service->url}}/8d9c8b3182023463c3470b19e7b4dad2511868cc/" + selectedRowID, postData)

                        .done(function() {

                            $('#spinner').addClass('d-none');

                            invoiceTable.deleteRow(selectedRowID);

                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);
                        });
                    $('#material_menu_button').prop('disabled', true);
                }
            });


        })

        $(document).on('click', '#open_unitselection_button', function() {


            dialog = BootstrapDialog.show({
                title: 'Einheit auswählen',
                message: $('<div></div>').load('../../ba0cfd2e18e37e3b20f8d121a5a01d05951dd232/5ddb8c9ee285433c6034c2e62b3590242eb2f82c'),
                type:BootstrapDialog.TYPE_LIGHT
            });

        });


        $('.preview_invoice').click(function() {

            window.location = "../../preview_invoice/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}";

        })

        $('.finish_invoice').click(function() {

            //window.location = "";
            dialog = BootstrapDialog.confirm({
                title: 'Hinweis',
                type: BootstrapDialog.TYPE_WARNING, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
                message: 'Wenn Sie die Rechnung schließen können keine weitere Änderungen an der Rechnung vorgenommen werden. Nach dem Schließen dieser Rechnung können Sie diese noch drucken oder per Email versenden. Rechnung jetzt schließen?',
                closable: true, // <-- Default value is false
                draggable: true, // <-- Default value is false
                btnCancelLabel: 'Abbrechen', // <-- Default value is 'Cancel',
                btnOKLabel: 'Rechnung schließen', // <-- Default value is 'OK',
                btnOKClass: 'btn-warning', // <-- If you didn't specify it, dialog type will be used,
                callback: function(result) {
                    // result will be true if button was click, while it will be false if users close the dialog directly.
                    if(result) {

                        $('#spinner').removeClass('d-none');

                        $.get("../../finish_invoice/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}")

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            window.location.reload();
                            dialogItself.close();

                        })

                        .fail(function(xhr, status, error) {

                            alertException(xhr);

                        });
                    }
                }
            });

        })

        $('.pdf_print').click(function() {


            window.location = "../../print_invoice/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}";



        })

        $('.send_email').click(function() {

            BootstrapDialog.show({
                message: $('<div></div>').load('../../f0d1d47eb92f01077335f4854cafd4f9b8c65197/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}'),
                title:'Email-Versand',
                type:BootstrapDialog.TYPE_LIGHT,
                buttons: [{
                    label: 'Senden',
                    cssClass:'btn-success',
                    action: function(dialogItself) {

                        $('#spinner').removeClass('d-none');

                        let postData = $('#new_email').serialize();

                            postData._token = '{{csrf_token()}}';

                        $.post("../../mail_invoice/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            dialogItself.close();

                        })

                        .fail(function(xhr, status, error) {

                            $('#spinner').addClass('d-none');


                             if(422 == xhr.status) {
                                $('#new_email').find('.is-invalid').removeClass('is-invalid');
                                $.each(xhr.responseJSON.errors, function(index, item) {
                                    let array = index.split('.');
                                    $('#new_email').find('[name="data['+array[1]+']"]').addClass('is-invalid');
                                });


                            }

                            else alertException(xhr);

                        });

                    }
                }, {
                    label: 'Abbrechen',
                    action: function(dialogItself){
                        dialogItself.close();
                    }
                }]
            });

        })

        $('.create_reverse_invoice').click(function() {

            dialog = BootstrapDialog.confirm({
                title: 'Hinweis',
                type: BootstrapDialog.TYPE_WARNING,
                message: 'Möchten Sie die aktuelle Rechnung stornieren? Wenn Sie auf JA klicken, wird automatisch eine Storno-Rechnung erstellt.',
                closable: true, // <-- Default value is false
                draggable: true, // <-- Default value is false
                btnCancelLabel: 'Abbrechen', // <-- Default value is 'Cancel',
                btnOKLabel: 'Stornorechnung erstellen', // <-- Default value is 'OK',
                btnOKClass: 'btn-warning', // <-- If you didn't specify it, dialog type will be used,
                callback: function(result) {
                    // result will be true if button was click, while it will be false if users close the dialog directly.
                    if(result) {

                        $('#spinner').removeClass('d-none');

                        $.post("../../create_reverse_invoice/{{$model->getKey()}}")

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            window.location.reload();
                            dialogItself.close();

                        })

                        .fail(function(xhr, status, error) {

                            alertException(xhr);

                        });
                    }
                }
            });

        })


        $('.create_adjusted_invoice').click(function() {

            dialog = BootstrapDialog.confirm({
                title: 'Hinweis',
                type: BootstrapDialog.TYPE_WARNING,
                message: 'Möchten Sie die aktuelle Rechnung berichtigen? Wenn Sie auf JA klicken, wird automatisch eine Berichtigungs-Rechnung erstellt.',
                closable: true, // <-- Default value is false
                draggable: true, // <-- Default value is false
                btnCancelLabel: 'Abbrechen', // <-- Default value is 'Cancel',
                btnOKLabel: 'Berichtigungsrechnung erstellen', // <-- Default value is 'OK',
                btnOKClass: 'btn-warning', // <-- If you didn't specify it, dialog type will be used,
                callback: function(result) {
                    // result will be true if button was click, while it will be false if users close the dialog directly.
                    if(result) {

                        $('#spinner').removeClass('d-none');

                        $.post("../../create_adjusted_invoice/{{$model->getKey()}}")

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            window.location.reload();
                            dialogItself.close();

                        })

                        .fail(function(xhr, status, error) {

                            alertException(xhr);

                        });
                    }
                }
            });

        })



        $('#fare,#location,#commission_number,#note,#order_number,#date,#service_date').editable({ onblur:"ignore", emptytext:'Klicken zum ändern', disabled:{{$model->invoice_number ? "true" : "false"}}});

        $('#header').editable({
            tpl: "<textarea type='text' style='width:800px'></textarea>"
        });

        $('#service_date').on('save', function(e, params) {

            $('#spinner').removeClass('d-none');

            let postData = {
                _token:'{{csrf_token()}}',
                _method: 'PUT',
                data: {}
            }

            postData.data['service_date'] = params.newValue;

            $.post("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                .done(function(data) {

                    $('#spinner').addClass('d-none');
                    $('#service_date').html(moment(data[0].service_date).format('DD.MM.YYYY'));
                })

                .fail(function(xhr) {

                    $('#spinner').addClass('d-none');

                    alertException(xhr);
                });

        });

        $('#date').on('save', function(e, params) {

            $('#spinner').removeClass('d-none');

            let postData = {
                _token:'{{csrf_token()}}',
                _method: 'PUT',
                data: {}
            }

            postData.data['date'] = params.newValue;

            $.post("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                .done(function(data) {

                    $('#spinner').addClass('d-none');
                    $('#date').html(moment(data[0].date).format('DD.MM.YYYY'));

                })

                .fail(function(xhr) {

                    $('#spinner').addClass('d-none');

                    alertException(xhr);
                });

        });

        $('#header').on('save', function(e, params) {

            $('#spinner').removeClass('d-none');

            let postData = {
                _token:'{{csrf_token()}}',
                _method: 'PUT',
                data: {}
            }

            postData.data['header'] = params.newValue;

            $.post("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                .done(function() {

                    $('#spinner').addClass('d-none');

                })

                .fail(function(xhr) {

                    $('#spinner').addClass('d-none');

                    alertException(xhr);
                });

        });


        $('#note').on('save', function(e, params) {

            $('#spinner').removeClass('d-none');

            let postData = {
                _token:'{{csrf_token()}}',
                _method: 'PUT',
                data: {}
            }

            postData.data['note'] = params.newValue;

            $.post("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                .done(function() {

                    $('#spinner').addClass('d-none');

                })

                .fail(function(xhr) {

                    $('#spinner').addClass('d-none');

                    alertException(xhr);
                });
        });

        $('#print_note').change(function() {

            $('#spinner').removeClass('d-none');

            let postData = {
                _token:'{{csrf_token()}}',
                _method: 'PUT',
                data: {}
            }

            postData.data['print_note'] = $('#print_note').prop('checked') ? 1 : 0;

            $.post("../../../api/{{$repository->getConfig()->_service->url}}/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}", postData)

                .done(function() {

                    $('#spinner').addClass('d-none');

                })

                .fail(function(xhr) {

                    $('#spinner').addClass('d-none');

                    alertException(xhr);
                });

        });


        $('.create_standing_order').on('click', function() {

            BootstrapDialog.confirm('Möchten Sie die aktuelle Rechnung als Dauerauftrag anlegen?', function(result){
                if(result) {

                    $('#spinner').removeClass('d-none');

                    let postData = {
                        _token:'{{csrf_token()}}',
                        _method: 'POST',
                    }

                    $.post("../../create_standing_order/{{$model->getKey()}}", postData)

                        .done(function(data) {

                            $('#spinner').addClass('d-none');
                            window.location = "../../137a983681de4ff7f08ec43c875cb00161efc24a/27b96af59ee924f9ec98cf9c44b54e06219636c1/" + data[0].ID;


                        })

                        .fail(function(xhr) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);
                        });

                }
            });


        });



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

        return;
            BootstrapDialog.show({
                message: $('<div></div>').load('../../1c09c602ecc905155d989319c7f8f116600af860/86343e16c8551a46bdd6560814444580b3833a53'),
                title:'Rechnungsadresse ändern',
                buttons: [{
                    label: 'Speichern',
                    action: function(dialogItself) {

                        $('#spinner').removeClass('d-none');

                        let ids = $.map($('#client_select_table').bootstrapTable('getSelections'), function (row) {
                            return row.ID
                        })

                        let postData = {};
                            postData._method = "PUT";
                            postData.data = {};
                            postData.data['_client'] = ids[0];

                        $.post("../../../api/{{$repository->getConfig()->_service->url}}/afe4f16263308b092d15e04719f202efe1326813/{{$model->getKey()}}", postData)

                        .done(function(data) {
                            $('#spinner').addClass('d-none');
                            dialogItself.close();
                            window.location.reload();
                        })

                        .fail(function(xhr, status, error) {

                            $('#spinner').addClass('d-none');

                            alertException(xhr);

                        });

                    }
                }, {
                    label: 'Abbrechen',
                    action: function(dialogItself){
                        dialogItself.close();
                    }
                }]
            });

        });


    });




    </script>

    </head>


    <body class="bg-light">

        <div id="spinner" class="spinner spinner-border d-none" role="status">
            <span class="sr-only">Loading...</span>
        </div>

          <div class="container bg-white border-left border-right  border-warning">

        <div class="btn-group mt-2 mb-2" role="group">

            <button type="image" class="btn btn-warning" style="color:white !important;" onclick="window.location='../../854e5746f03aaac88bb0e294185f2f14f168af43'"><img src="/images/logo_hell.png" widht=20 height=20/> Startseite</button>

            <button type="button" class="btn btn-warning" style="color:white !important; background-color:var(--warning); opacity:1" onclick="window.location = '../854e5746f03aaac88bb0e294185f2f14f168af43'" disabled><b>Rechnungswesen</b></button>

            <button type="button" class="btn btn-warning" onclick="window.location='../../759549c6ca5f53b6c47699785cbd2ca0aa8438e4/afe4f16263308b092d15e04719f202efe1326813'"><i class="mdi mdi-home-circle"></i> zurück zur Übersicht</button>
            <button class="btn btn-warning dropdown-toggle" type="button" data-toggle="dropdown">
                Rechnung
            </button>
            <div class="dropdown-menu">
                <a class="dropdown-item preview_invoice @if($model->flag_finished) disabled @endif" href="#">Vorschau</a>
                @if(!$model->invoice_number)
                <div class="dropdown-divider"></div>
                <a class="dropdown-item finish_invoice" href="#">Rechnung abschließen</a>
                @if("standing_order" != $model->_meta->_doctype->identifier)
                <a class="dropdown-item create_standing_order" href="#">Dauerauftrag anlegen</a>
                @endif
                @else
                <a class="dropdown-item pdf_print" href="#">@if($model->printed) erneut @endif Drucken</a>
                @if($MAIL_HOST)
                <a class="dropdown-item send_email" href="#">@if($model->mailed) erneut @endif per Email senden</a>
                @endif
                @if($model->printed OR $model->mailed)
                <a class="dropdown-item create_reverse_invoice" href="#">Rechnung stornieren</a>
                <a class="dropdown-item create_adjusted_invoice" href="#">Rechnung berichtigen</a>
                @endif
                @endif
                <div class="dropdown-divider"></div>
                <a class="dropdown-item drop_invoice @if($model->flag_finished) disabled @endif" href="#">Löschen</a>
            </div>
        </div>



            <div class="row">

                <div class="col col-xs-12 col-md-4">

                    <div class="card">
                            <ul class="list-group list-group-flush">
                            <li class="list-group-item"><b>Rechnung</b></li>
                            <li class="list-group-item">
                                <b>{{$model->client}}</b>
                                @if($model->firstname) <br> {{$model->firstname}} {{$model->surname}} @endif
                                <br>{{$model->streetadress}} {{$model->housenumber}}
                                <br>{{$model->postcode}} {{$model->location}}
                            </li>
                        </ul>
                    </div>
                </div>


                <div class="col col-xs-12 col-md-4">
                    <div class="card">
                            <ul class="list-group list-group-flush">
                            <li class="list-group-item"><b>Notizen:</b></b> <small>(auf PDF drucken <input type="checkbox" name="data[print_note]" id="print_note" {{$model->print_note ? 'checked="checked"' : ''}}>)</small></li>
                            @if(!$model->invoice_number)
                            <li class="list-group-item"><a href="#" id="note" data-type="textarea" data-mode="inline">{{$model->note}}</a></li>
                            @else
                            <li class="list-group-item">{!! nl2br($model->note)!!}</li>
                            @endif
                        </ul>
                    </div>

                </div>
                <div class="col col-xs-12 col-md-4">
                    <div class="card">
                            <ul class="list-group list-group-flush">
                            @if(!$model->invoice_number)
                            <li class="list-group-item" style="font-size:x-large"><b>Dauerauftrag-Nr:</b> <b class="text-warning">[{{$model->createInvoiceNumber()}}]</b></li>
                            @else
                            <li class="list-group-item" style="font-size:x-large"><b>Dauerauftrag-Nr:</b> <b class="text-warning">{{$model->invoice_number}}</b></li>
                            @endif
                            @if($model->_ticket->getKey() AND "Angebot" == $model->_ticket->descriptor)
                            <li class="list-group-item"><b>{{$model->_ticket->descriptor}}:</b> <a href="../../d774d83528528c1bb8aa3f8a18d6bd66a9c76e66/afe4f16263308b092d15e04719f202efe1326813/{{$model->_ticket->getKey()}}"  style="color:var(--cyan)">{{$model->_ticket->job_number}}</a></li>
                            @elseif($model->_ticket->getKey())
                            <li class="list-group-item"><b>{{$model->_ticket->descriptor}}:</b> <a href="../../0ff1bb77a9de65eac6621c9c5a983da7a37ed3bf/afe4f16263308b092d15e04719f202efe1326813/{{$model->_ticket->getKey()}}"  style="color:var(--cyan)">{{$model->_ticket->job_number}}</a></li>
                            @endif
                            <li class="list-group-item"><b>Gesendet:</b> @if($model->mailed) {{(new \Carbon\Carbon($model->mailed))->format('d.m.Y')}} @endif</li>
                            <li class="list-group-item"><b>Gedruckt:</b> @if($model->printed) {{(new \Carbon\Carbon($model->printed))->format('d.m.Y')}} @endif</li>
                            <li class="list-group-item"><b>Leistungsdatum:</b> <a href="#" id="service_date" data-tpl="<input type='date'>" data-mode="inline" data-value="{{$model->service_date}}" data-emptytext ="Heute">@if($model->service_date) {{(new \Carbon\Carbon($model->service_date))->format('d.m.Y')}} @endif</a></li>

                            <li class="list-group-item"><b>Rechnungsdatum:</b> <a href="#" id="date" data-tpl="<input type='date'>" data-mode="inline" data-value="{{$model->date}}" data-emptytext ="Heute">@if($model->date) {{(new \Carbon\Carbon($model->date))->format('d.m.Y')}} @endif</a></li>
                            @if($model->_reverse_invoice)
                            <li class="list-group-item"><b>Stornodatum:</b> {{(new \Carbon\Carbon($model->_reverse_invoice->date))->format('d.m.Y')}}</li>
                            @endif

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

            @if($model->_reverse_invoice)
            <div class="card mt-2">
                <div class="card-header bg-warning text-white">Hinweis</div>
                <div class="card-body bg-warning text-white">

                    Diese Rechnung wurde storniert. Die Stornorechnung finden Sie <a class="text-white" href="../../2fc25ddce687403194c3995a6f3bcdcebb62968d/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->_reverse_invoice->getKey()}}">hier</a>.

                </div>
            </div>
            @endif

            <hr>

            <div class="card mt-2">
                <div class="card-header">Anschreiben </div>
                <div class="card-body">

                    @if(!$model->flag_finished)

                    <a href="#" id="header" data-type="textarea" data-mode="inline">{!!$model->header!!}</a>

                    @else

                    @foreach(explode("\n", $model->header) as $line) {{ $line }} <br> @endforeach

                    @endif
                </div>
            </div>



            <div class="card mt-2">
                <div class="card-header">Arbeitsstunden</div>
                <div class="card-body">

                    @if(!$model->flag_finished)
                    <div class="btn-group mt-2" role="group" aria-label="Basic example">

                        <button type="button" class="btn btn-secondary" id="add_ae"><i class="bi bi-file-plus"></i></button>


                        <div class="dropdown ml-1">
                            <button class="btn btn-secondary dropdown-toggle" type="button" id="ae_menu_button" data-toggle="dropdown" aria-expanded="false" disabled>
                            Auswahl
                            </button>
                            <div class="dropdown-menu">
                                <button class="dropdown-item" id="drop_ae_button">Löschen</button>
                            </div>
                        </div>



                    </div>

                    @endif
                </div>
                <div id="aeTable" class="mt-3"></div>
            </div>

            <div class="card mt-2">
                <div class="card-header">Fahrtkosten</div>
                <div class="card-body">

                    @if(!$model->flag_finished)
                    <div class="btn-group mt-2" role="group" aria-label="Basic example">

                        <button type="button" class="btn btn-secondary" id="add_fare"><i class="bi bi-file-plus"></i></button>


                        <div class="dropdown ml-1">
                            <button class="btn btn-secondary dropdown-toggle" type="button" id="fare_menu_button" data-toggle="dropdown" aria-expanded="false" disabled>
                            Auswahl
                            </button>
                            <div class="dropdown-menu">
                                <button class="dropdown-item" id="drop_fare_button">Löschen</button>
                            </div>
                        </div>



                    </div>

                    @endif
                </div>
                <div id="fareTable" class="mt-3"></div>
            </div>



            <div class="card mt-2">
                <div class="card-header">Material</div>
                <div class="card-body">

                    @if(!$model->flag_finished)
                    <div class="btn-group mt-2" role="group" aria-label="Basic example">

                        <button type="button" class="btn btn-secondary" id="add_material"><i class="bi bi-file-plus"></i></button>


                        <div class="dropdown ml-1">
                            <button class="btn btn-secondary dropdown-toggle" type="button" id="material_menu_button" data-toggle="dropdown" aria-expanded="false" disabled>
                            Auswahl
                            </button>
                            <div class="dropdown-menu">
                                <button class="dropdown-item" id="drop_material_button">Löschen</button>
                            </div>
                        </div>



                    </div>

                    @endif
                </div>
                <div id="invoiceTable" class="mt-3"></div>

        </div>

        <div class="card mt-2">
            <div class="card-header gesamt font-weight-bold text-right pr-5">
                <div class="netto_gesamt">0.00€</div>
                @if(!$editor->getValue('COMPANY_SBLAW'))<div class="brutto">0.00€</div>@endif
            </div>
        </div>

         <div class="card mt-2">
                <div class="card-header">Rechnungstext</div>
                <div class="card-body">

                    @if(!$model->flag_finished)
                    <div class="btn-group mt-2" role="group" aria-label="Basic example">

                        <button type="button" class="btn btn-secondary" id="add_invoice_text"><i class="bi bi-file-plus"></i></button>


                        <div class="dropdown ml-1">
                            <button class="btn btn-secondary dropdown-toggle" type="button" id="invoice_text_menu_button" data-toggle="dropdown" aria-expanded="false" disabled>
                            Auswahl
                            </button>
                            <div class="dropdown-menu">
                                <button class="dropdown-item" id="drop_invoice_text_button">Löschen</button>
                            </div>
                        </div>



                    </div>

                    @endif
                </div>
                <div id="invoiceTextTable" class="mt-3"></div>
            </div>


         <div class="card mt-2">
                <div class="card-header">Dokument</div>
                <div class="card-body text-right">
                    @if(!$model->invoice_number)
                    <button class="btn btn-warning finish_invoice">Rechnung abschließen</a>
                    @else
                    <button class="btn btn-warning pdf_print">@if($model->printed) erneut @endif Drucken</button>
                        @if($MAIL_HOST)
                        <button class="btn btn-warning send_email">@if($model->mailed) erneut @endif per Email senden</button>
                        @endif
                    @endif
                </div>
            </div>

        </div>


    </div>
    </body>
</html>

