<!doctype html>
<?php 

use Carbon\Carbon;
use Jackiedo\DotenvEditor\Facades\DotenvEditor;


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

$customer = \Runtime::make('hwplus_clients')->where('customer_id', $model->customer_id)->first();

?>
<html lang="en" class="h-100">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Mahnwesen - {{$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')}}">
    
   
    <script>

    $(function() {
    
        $('.send_email').click(function() {
      
            BootstrapDialog.show({
                message: $('<div></div>').load('../../2b18afd4b0a7d864554972d17b0be9b25f7ff141/27b96af59ee924f9ec98cf9c44b54e06219636c1/{{$model->getKey()}}'),
                title:'Mahnung versenden',
                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_dunning_letter/{{$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();
                    }
                }]
            });
        
        })
    
    })
    
       
    </script>
    
    </head> 

    <body class="bg-transparent">
    
        <div id="spinner" class="spinner spinner-border d-none" role="status">
            <span class="sr-only">Loading...</span>
        </div>
    
        <div class="container pt-3 bg-white e border-left border-right" style="border-color:var(--pink)">
          
        <nav class="navbar navbar-expand-lg navbar-light text-white" style="background-color:var(--pink)">
            <a class="navbar-brand text-white" href="#"><i class="mdi mdi-reminder"></i> Mahnwesen</a>
        </nav>


        <div class="btn-group mt-2 mb-2" role="group">
    
            <button type="image" class="btn" style="color:white !important; background-color:var(--pink)" onclick="window.location='../../854e5746f03aaac88bb0e294185f2f14f168af43'"><img src="/images/logo_hell.png" widht=20 height=20/> Startseite</button>
    
            <button type="button" class="btn" style="color:white !important; background-color:var(--pink); opacity:1" onclick="window.location = '../854e5746f03aaac88bb0e294185f2f14f168af43'" disabled><b>Rechnungswesen</b></button>
         
            <button type="button" class="btn text-white" style="background-color:var(--pink)" onclick="window.location='../../d32440f095831b1caac7fb01939bde8933da116b/afe4f16263308b092d15e04719f202efe1326813'"><i class="mdi mdi-home-circle"></i> zurück zur Übersicht</button>
            <button class="btn dropdown-toggle text-white" style="background-color:var(--pink)" type="button" data-toggle="dropdown">
                Mahnung
            </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
                @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>RG-Nummer:</b> <b class="text-danger">[{{$model->createInvoiceNumber()}}]</b></li>
                            @else
                            <li class="list-group-item" style="font-size:x-large"><b>RG-Nummer:</b> <b class="text-danger">{{$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>
                        </ul>
                    </div>
                </div>
            </div>
            


            <div class="row mt-5">

                <div class="col col-4">

                    <div class="card mt-2">
                        <div class="card-header">Zahlungerinnerung</div>
                        <div class="card-body">
                            @php
                                $due_date = (new Carbon($model->date))->addDays($customer->_payment_term->days_to_remind);
                                $date_reminded =  (new Carbon($model->date_payment_reminder));
                                @endphp

                            Zahlungseingang fällig bis: {{ $due_date->format('d.m.Y') }}<br>

                            Status:             @if($due_date <= now()) Frist verstrichen
                                                @else wartend auf Zahlungseingang
                                                @endif<br>

                            @if($model->date_payment_reminder) Mahnung gesendet: {{ $date_reminded->format('d.m.Y') }}
                            @elseif($due_date > now())
                            @else <button type="button" class="btn btn-danger send_email">Jetzt Mahnung senden</button>
                            @endif

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

                <div class="col col-4">

                    <div class="card mt-2">
                        <div class="card-header">Zahlungsaufforderung</div>
                        <div class="card-body">
                            @php
                                $due_date = (new Carbon($model->date))->addDays($customer->_payment_term->days_to_demand);
                                $date_reminded =  (new Carbon($model->date_demand_for_payment));
                                @endphp

                            Zahlungseingang fällig bis: {{ $due_date->format('d.m.Y') }}<br>

                            Status:             @if($due_date <= now()) Frist verstrichen
                                                @else wartend auf Zahlungseingang
                                                @endif<br>

                            @if($model->date_demand_for_payment) Mahnung gesendet: {{ $date_reminded->format('d.m.Y') }}
                            @elseif($due_date > now())
                            @else <button type="button" class="btn btn-danger send_email">Jetzt Mahnung senden</button>
                            @endif

                        </div>
                    </div>

                </div>
                <div class="col col-4">
                    <div class="card mt-2">
                        <div class="card-header">Mahnung</div>
                        <div class="card-body">
                            @php
                                $due_date = (new Carbon($model->date))->addDays($customer->_payment_term->days_to_dunning_letter);
                                $date_reminded =  (new Carbon($model->date_dunning_letter));
                                @endphp

                            Zahlungseingang fällig bis: {{ $due_date->format('d.m.Y') }}<br>

                            Status:             @if($due_date <= now()) Frist verstrichen
                                                @else wartend auf Zahlungseingang
                                                @endif<br>

                            @if($model->date_dunning_letter) Mahnung gesendet: { $date_reminded->format('d.m.Y') }}
                            @elseif($due_date > now())
                            @else <button type="button" class="btn btn-danger send_email">Jetzt Mahnung senden</button>
                            @endif

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

            </div>
            




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