
<div class="card">
    <!-- Status -->
    <div class="card-body">
        <div class="row">
            <div class="col-md-6 mb-1">
                <strong class="mr-2">Status:</strong>
                <span class="text-big">
                        {!! \App\Services\Payment::getShoppingOrderBadge($shopping_order); !!}
                    </span>
            </div>
            <div class="col-md-6 mb-1">
                <strong class="mr-2">Versand:</strong>

                @if($isAdmin)
                    <button type="button" class="btn btn-sm btn-{{$shopping_order->getShippedColor()}}" data-toggle="modal" data-target="#modals-shipped"
                            data-id="{{ $shopping_order->id }}"
                            data-shipped="{{ $shopping_order->shipped }}"
                            data-back="{{url()->current()}}"
                            data-action="store_shipped">
                        <span class="far fa-edit"></span> <strong>{{$shopping_order->getShippedType()}}</strong>
                    </button>
                @else
                    <span class="text-big">
                       <span class="badge badge-pill badge-{{$shopping_order->getShippedColor()}}">{{$shopping_order->getShippedType()}}</span>
                    </span>
                @endif
            </div>
        </div>

    </div>
    <hr class="m-0">
    <!-- / Status -->

    <!-- Info -->
    <div class="card-body pb-1">
        <div class="row">
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Bestelldatum</div>
                {{$shopping_order->created_at->format("d.m.Y H:i")}}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Anzahl Artikel</div>
                {{$shopping_order->getItemsCount()}}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Preis gesamt</div>
                {{$shopping_order->getFormattedTotalShipping()}} &euro;
            </div>
            <div class="col-md-3 mb-3">
               {{--  <div class="text-muted small">Points gesamt</div>
                {{ $shopping_order->points }}
                --}}
            </div>
        </div>
    </div>
    <hr class="m-0">
    <!-- / Info -->

@if($isAdmin)
    <!-- Member -->
        <div class="card-body pb-1">
            <div class="row">
                <div class="col-md-8 mb-3">
                    @if(isset($change_member_error) && $change_member_error)
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="alert alert-danger p-2">
                                    <ul>
                                        <li>{{ $change_member_error }}</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    @endif
                    <div class="text-muted small">Zugewiesener Vertriebspartner</div>
                    @if($isView === 'sales_user')
                       {{-- @if($shopping_order->user_shop)
                            {{$shopping_order->user_shop->title}}
                        @endif
                        --}}
                    @endif

                    @if($isView === 'sales_customer')
                        @if($shopping_order->shopping_user && $shopping_order->shopping_user->is_like)
                            <button type="button" class="btn btn-xs btn-outline-info" data-toggle="modal" data-target="#modals-load-content"
                                    data-id="{{$shopping_order->shopping_user->id}}"
                                    data-action="shopping-user-is-like-member"
                                    data-back="{{route('admin_sales_customers_detail', [$shopping_order->id])}}"
                                    data-modal="modal-xl"
                                    data-route="{{route('modal_load')}}"><span class="fa fa-edit"></span> Vertriebspartner zuordnen</button>
                        @else
                            @if($shopping_order->member)
                                <a class="btn btn-xs btn-outline-primary" href="{{route('admin_lead_edit', [$shopping_order->member->id])}}"><i class="ion ion-ios-contacts"></i></a>
                                {{$shopping_order->member->getFullName()}} <span class="text-muted">#{{$shopping_order->member->number}}</span>
                            @endif
                            <button type="button" class="btn btn-xs btn-outline-secondary" data-toggle="modal" data-target="#modals-load-content"
                                    data-id="{{ $shopping_order->id }}"
                                    data-action="shopping-order-change-member"
                                    data-view="{{$isView}}"
                                    data-route="{{ route('modal_load') }}"><span class="fa fa-edit"></span></button>
                        @endif

                    @endif

                </div>
                <div class="col-md-4 mb-3">
                    <div class="text-muted small"></div>

                </div>
            </div>
        </div>
        <hr class="m-0">
        <!-- / Member -->
@endif

<!-- Billing -->
    <div class="card-body">

        <h6 class="small font-weight-semibold">
            @if($shopping_order->shopping_user->is_from === 'shopping' || $shopping_order->shopping_user->is_from === 'extern')
                Rechnungsadresse des Kunden
            @else
                Rechnungsadresse des Vertriebspartners
            @endif
        </h6>
        <div class="row">
            @if($shopping_order->shopping_user->billing_company)
                <div class="col-md-12 mb-3">
                    <div class="text-muted small">Firma</div>
                    {{ $shopping_order->shopping_user->billing_company }}
                </div>
            @endif

            <div class="col-md-3 mb-3">
                <div class="text-muted small">Anrede</div>
                {{ \App\Services\HTMLHelper::getSalutationLang($shopping_order->shopping_user->billing_salutation) }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Vorname</div>
                {{ $shopping_order->shopping_user->billing_firstname }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Nachname</div>
                {{ $shopping_order->shopping_user->billing_lastname }}
            </div>
        </div>
        <div class="row">
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Straße</div>
                {{ $shopping_order->shopping_user->billing_address }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Zusatz</div>
                {{ $shopping_order->shopping_user->billing_address_2 }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">PLZ</div>
                {{ $shopping_order->shopping_user->billing_zipcode }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Stadt</div>
                {{ $shopping_order->shopping_user->billing_city }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">E-Mail</div>
                {{ $shopping_order->shopping_user->billing_email }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Telefon</div>
                {{ $shopping_order->shopping_user->billing_phone }}
            </div>
            <div class="col-md-3 mb-3">
                <div class="text-muted small">Land</div>
                {{ $shopping_order->shopping_user->billing_country->getLocated() }}
            </div>
        </div>
    </div>
    <!-- / Billing -->

    <!-- Shipping -->
    @if($shopping_order->shopping_user->is_from !== 'homeparty')
        <hr class="m-0">

        <div class="card-body">
            <h6 class="small font-weight-semibold">
                @if($shopping_order->shopping_user->is_from === 'user_order' || $shopping_order->shopping_user->is_from === 'extern')
                    @if($shopping_order->shopping_user->is_for === 'me')
                        Lieferadresse des Vertriebspartner
                    @else
                        Lieferadresse des Kunden
                    @endif
                @endif
                @if($shopping_order->shopping_user->is_from === 'wizard')
                    Lieferadresse des Vertriebspartner
                @endif
                @if($shopping_order->shopping_user->is_from === 'membership')
                    Lieferadresse des Vertriebspartner
                @endif
                @if($shopping_order->shopping_user->is_from === 'shopping')
                    Lieferadresse des Kunden
                @endif
            </h6>
            @if($shopping_order->shopping_user->same_as_billing)
                {{__('email.checkout_mail_same_address')}}
            @else
                <div class="row">
                    @if($shopping_order->shopping_user->shipping_company)
                        <div class="col-md-12 mb-3">
                            <div class="text-muted small">Firma</div>
                            {{ $shopping_order->shopping_user->shipping_company }}
                        </div>
                    @endif

                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Anrede</div>
                        {{ \App\Services\HTMLHelper::getSalutationLang($shopping_order->shopping_user->shipping_salutation) }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Vorname</div>
                        {{ $shopping_order->shopping_user->shipping_firstname }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Nachname</div>
                        {{ $shopping_order->shopping_user->shipping_lastname }}
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Straße</div>
                        {{ $shopping_order->shopping_user->shipping_address }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Zusatz</div>
                        {{ $shopping_order->shopping_user->shipping_address_2 }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">PLZ</div>
                        {{ $shopping_order->shopping_user->shipping_zipcode }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Stadt</div>
                        {{ $shopping_order->shopping_user->shipping_city }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">E-Mail</div>
                        {{ $shopping_order->shopping_user->shipping_email }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Telefon</div>
                        {{ $shopping_order->shopping_user->shipping_phone }}
                    </div>
                    <div class="col-md-3 mb-3">
                        <div class="text-muted small">Land</div>
                        {{ $shopping_order->shopping_user->shipping_country->getLocated() }}
                    </div>
                </div>
            @endif
        </div>
    @endif
    <hr class="m-0">
    <!-- / Shipping -->

    <!-- Items -->
    <div class="card-body">
        <h6 class="small font-weight-semibold">
            @if($shopping_order->shopping_user->is_from === 'user_order')
                @if($shopping_order->shopping_user->is_for === 'me')
                    <strong>Bestellung für Vertriebspartner</strong>
                @else
                    <strong>Bestellung für Kunde</strong>
                @endif
            @endif
            @if($shopping_order->shopping_user->is_from === 'wizard')
                <strong>Vertriebspartnerbestellung für Registrierung</strong>
            @endif
            @if($shopping_order->shopping_user->is_from === 'membership')
                <strong>Vertriebspartnerbestellung für Mitgliedschaft</strong>
            @endif
            @if($shopping_order->shopping_user->is_from === 'shopping')
                <strong>Kundenbestellung über Shop</strong>
            @endif
            @if($shopping_order->shopping_user->is_from === 'homeparty')
                <h5>Vertriebspartnerbestellung für eine Homeparty</h5>
                <hr>
            @endif
        </h6>
        <style>
            table.table-product, table.table-product tr td, table.table-product tr th {
                border:none;
            }
            table.table-product tr.border-top td {
                border-top: 1px solid #b8b8b9;
            }
            table.table-product tr.border-bottom td, table.table-product tr.border-bottom th {
                border-bottom: 1px solid #b8b8b9;
            }

        </style>

            <div class="table-responsive">
                <table class="table table-product m-0" style="">
                    <tbody>
                    <tr class="border-bottom">
                        <th>Produkt</th>
                        <th class="text-right">
                            @if($shopping_order->shopping_user->is_from === 'user_order')
                                Netto-Preis
                            @else
                                Preis
                            @endif
                        </th>
                        <th class="text-right">Anzahl</th>
                        <th class="text-right">Summe</th>
                    </tr>
                    @foreach($shopping_order->shopping_order_items as $shopping_order_item)
                        <tr class="border-bottom">
                            <td class="px-3 py-2">
                                <div class="media align-items-center">
                                    @if($shopping_order_item->product)
                                        @if($shopping_order_item->product->images)
                                            @if($image = $shopping_order_item->product->images->first())
                                                <img src="{{ route('product_image', [$image->slug]) }}" class="d-block ui-w-80 mr-4" alt>
                                            @endif
                                        @endif

                                        <div class="media-body">
                                            <a href="{{route('admin_product_edit', [$shopping_order_item->product->id])}}" class="d-block">{{ $shopping_order_item->product->name }}
                                                <span class="text-muted">#{{ $shopping_order_item->product->number }}</span></a>
                                            <small>
                                                <span class="text-muted">Inhalt: </span> {{ $shopping_order_item->product->contents }}<br>
                                                <span class="text-muted">Gewicht: </span> {{ $shopping_order_item->product->weight }} g<br>
                                                {{-- <span class="text-muted">Points: </span> {{ $shopping_order_item->product->points }} --}}
                                            </small>
                                        </div>
                                    @endif
                                </div>
                            </td>
                            <td class="align-middle px-3 py-2 nowrap text-right" style="min-width:100px;">
                                @if($shopping_order->shopping_user->is_from === 'user_order')
                                {{ $shopping_order_item->getFormattedPriceNet() }} &euro;
                                @else
                                {{ $shopping_order_item->getFormattedPrice() }} &euro;
                                @endif
                            </td>
                            <!-- Set column width -->
                            <td class="align-middle px-3 py-2 text-right" style="min-width: 60px;">
                                {{ $shopping_order_item->qty }}
                            </td>
                            <!-- Set column width -->
                            <td class="font-weight-semibold align-middle px-3 py-2 text-right" style="min-width:120px;">
                                @if($shopping_order->shopping_user->is_from === 'user_order')
                                {{ $shopping_order_item->getFormattedTotalPriceNet() }} &euro;
                                @else
                                {{ $shopping_order_item->getFormattedTotalPrice() }} &euro;
                                @endif
                            </td>
                        </tr>
                    @endforeach

                    </tbody>
                    <tfoot>
                    <style>
                        .table_small_td {
                            padding-top: 0.125rem !important;
                        }
                    </style>
                    @if($shopping_order->shopping_user->is_from === 'user_order')
                    <tr class="">
                        <td colspan="3">
                            Zwischensumme
                        </td>
                        <td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                            {{ $shopping_order->getFormattedSubtotalFull() }} &euro;*
                        </td>
                    </tr>
                    <tr class="">
                        <td class="table_small_td" colspan="3">
                            Handelspanne
                        </td>
                        <td class="table_small_td" style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                            - {{ $shopping_order->getFormattedDiscount() }} &euro;*
                        </td>
                    </tr>
                    <tr class="border-bottom">
                        <td class="table_small_td" colspan="3">
                           <strong>Summe (Netto)</strong>
                        </td>
                        <td class="table_small_td" style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                            <strong>{{ $shopping_order->getFormattedSubtotal() }} &euro;*</strong>
                        </td>
                    </tr>
                    @endif

                    <tr class="border-bottom">
                        <td colspan="3">
                            {{__('email.checkout_mail_shipping')}}
                        </td>
                        <td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.4em;">
                            @if($shopping_order->shopping_user->is_from === 'user_order')
                            {{ $shopping_order->getFormattedShippingNet() }} &euro;*
                            @else
                            {{ $shopping_order->getFormattedShipping() }} &euro;
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            {{__('email.checkout_mail_subtotal_ws')}}
                        </td>
                        <td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                            {{ $shopping_order->getFormattedSubtotalShipping() }} &euro;*
                        </td>
                    </tr>
                    <tr class="border-bottom">
                        <td class="table_small_td" colspan="3">
                            {{__('email.checkout_mail_tax')}}
                        </td>
                        <td class="table_small_td" style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                            {{ $shopping_order->getFormattedTax() }} &euro;
                        </td>
                    </tr>
                    @if($shopping_order->shopping_user->is_from === 'user_order' && $shopping_order->payment_credit > 0)
                        <tr>
                            <td colspan="3">
                               <b> Summe (Brutto):</b>
                            </td>
                            <td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                               <b> {{ $shopping_order->getFormattedTotalWithoutCredit() }} &euro;</b>
                            </td>
                        </tr>
                        <tr class="border-bottom">
                            <td class="table_small_td" colspan="3">
                                aus Guthaben (Brutto):
                            </td>
                            <td class="table_small_td" style="color:#37302d; text-align: right; vertical-align: top;line-height:1.2em;">
                                {{ $shopping_order->getFormattedPaymentCredit() }} &euro;
                            </td>
                        </tr>
                        @endif
                    <tr>
                        <td colspan="3">
                            <b>Gesamtsumme (Brutto):</b>
                        </td>
                        <td style="color:#37302d; text-align: right; vertical-align: top;line-height:1.4em;">
                            <b>{{ $shopping_order->getFormattedTotalShipping() }} &euro;</b>
                            <br>
                            <span style="font-size: 0.9em"><em>* Nettobeträge</em></span>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
    </div>
    <hr class="m-0">

    @if($shopping_order->txaction === 'extern')
        <div class="card-body">
            @if($shopping_order->wp_invoice_path)
                <div class="row">
                    <div class="col-sm-12">
                        <a href="{{$shopping_order->wp_invoice_path}}" target="_blank" class="btn btn-secondary btn-sm">Link zur Rechnung</a>
                    </div>
                </div>
            @endif
            @if($shopping_order->wp_notice['wp_advertising'])
                <div class="row">
                    <div class="col-sm-12">
                        <b>Werbemittel: {!! $shopping_order->wp_notice['wp_advertising'] !!}<br></b>
                    </div>
                </div>
            @endif
            @if($shopping_order->wp_notice['wp_incentives'])
                <div class="row">
                    <div class="col-sm-12">
                        <b>Incentives: {!! $shopping_order->wp_notice['wp_incentives'] !!}<br></b>
                    </div>
                </div>
            @endif
        </div>
        <hr class="m-0">
@endif


    <div class="card-body">
        <h6 class="small font-weight-semibold">
            Zahlung
        </h6>
        @if($shopping_order->txaction !== 'extern')
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th style="min-width: 60px">#</th>
                        <th>Zahlungsart</th>
                        <th>Gesamt</th>
                        <th>Status</th>
                        <th>Datum</th>
                        <th>Referenznummer</th>
                    </tr>
                    </thead>
                    <tbody>
                    @php($count=0)
                    @foreach($shopping_order->shopping_payments as $shopping_payment)
                        <tr>
                            <th scope="row">{{++$count}}</th>
                            <td>{{$shopping_payment->getPaymentType()}}</td>
                            <td>{{$shopping_payment->getPaymentAmount()}}</td>
                            <td>
                                @if($isAdmin && ($shopping_payment->clearingtype === 'fnc' || $shopping_payment->clearingtype === 'vor'))
                                    <button type="button" class="btn btn-sm btn-{{ \App\Services\Payment::getFormattedTxactionColor($shopping_payment->txaction)}}" data-toggle="modal" data-target="#modals-txaction"
                                            data-id="{{ $shopping_order->id }}"
                                            data-payment_id="{{ $shopping_payment->id }}"
                                            data-txaction="{{ $shopping_payment->txaction }}"
                                            data-back="{{url()->current()}}"
                                            data-action="store_txaction">
                                        <span class="far fa-edit"></span> <strong>{{ \App\Services\Payment::getFormattedTxaction($shopping_payment->txaction)}}</strong>
                                    </button>
                                @else
                                    {!! \App\Services\Payment::getShoppingPaymentBadge($shopping_payment) !!}
                                @endif
                            </td>
                            <td>{{$shopping_payment->created_at->format("d.m.Y H:i")}}</td>
                            <td>{{$shopping_payment->reference}}</td>
                        </tr>
                        @if($isAdmin && $shopping_payment->payment_transactions)
                            @php($ccount=0)
                            <tr>
                                <th scope="row" class="m-0">{{$count}}.{{++$ccount}}</th>
                                <td colspan="5" class="m-0 p-0">
                                    <table class="table table-info table-borderless mb-0 small">
                                        <thead>
                                        <tr>
                                            <th style="min-width: 80px">Request</th>
                                            <th style="min-width: 80px">Status</th>
                                            <th style="min-width: 200px">TX-Action</th>
                                            <th style="min-width: 120px">Datum</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($shopping_payment->payment_transactions as $payment_transaction)
                                            <tr>
                                                <td>{{$payment_transaction->request}}</td>
                                                <td>{{$payment_transaction->status}}</td>
                                                <td>{{$payment_transaction->txaction}} {{$payment_transaction->errormessage}}</td>
                                                <td>{{$payment_transaction->created_at->format("d.m.Y H:i")}}</td>
                                            </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        @endif
                    @endforeach
                    </tbody>
                </table>
            </div>
        @else
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-info p-2 mt-2">
                        <ul>
                            <li>Bestellung über externen SHOP</li>
                        </ul>
                    </div>
                </div>
            </div>
        @endif
    </div>
</div>

@if($isAdmin)
    <div class="modal fade" id="modals-shipped">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('admin_sales_store') }}" method="post">
                @csrf
                <input type="hidden" name="id" value="{{$shopping_order->id}}">
                <input type="hidden" name="action" value="store_shipped">
                <input type="hidden" name="back" value="{{url()->current()}}">

                <div class="modal-header">
                    <h5 class="modal-title">{{__('Bestellung')}} {{__('Versand')}} </h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
                </div>
                <div class="modal-body">
                    <div class="form-group col-sm-12">
                        <label class="form-label" for="shipped">{{ __('Versand') }}</label>
                        {{ Form::select('shipped', \App\Models\ShoppingOrder::$shippedTypes, $shopping_order->shipped, array('data-live-search'=>'false', 'class'=>'selectpicker') ) }}
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
                    <button type="submit" class="btn btn-primary">{{__('save')}}</button>
                </div>
            </form>
        </div>
    </div>

    <div class="modal fade" id="modals-txaction">
        <div class="modal-dialog">
            <form class="modal-content" action="{{ route('admin_sales_store') }}" method="post">
                @csrf
                <input type="hidden" name="id" value="{{$shopping_order->id}}">
                <input type="hidden" name="payment_id">
                <input type="hidden" name="action" value="store_txaction">
                <input type="hidden" name="back" value="{{url()->current()}}">

                <div class="modal-header">
                    <h5 class="modal-title">{{__('Bestellung')}} {{__('Zahlung')}} </h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
                </div>
                <div class="modal-body">
                    <div class="form-group col-sm-12">
                        <label class="form-label" for="txaction">{{ __('Zahlung') }}</label>
                        {{ Form::select('txaction', \App\Services\Payment::$txaction_invoice, 'open', array('data-live-search'=>'false', 'class'=>'selectpicker') ) }}
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
                    <button type="submit" class="btn btn-primary">{{__('save')}}</button>
                </div>
            </form>
        </div>
    </div>


    <script>
        $( document ).ready(function() {
            $('#modals-txaction').on('show.bs.modal', function (event) {
                var button = $(event.relatedTarget);
                $(this).find(".modal-content input[name='payment_id']").val(button.data('payment_id'));
                $(this).find(".modal-body select[name='txaction']").val(button.data('txaction'));
                $('.selectpicker').selectpicker('refresh');

            });
        });
    </script>

@endif