<style type="text/css">
    * {
        font-size: {{ $settings['PrintSize'] }}px !important;
        font-family: 'Times New Roman';
        font-weight: bold;
    }

    .centered {
        text-align: center;
        align-content: center;
    }


    img {
        max-width: inherit;
        width: inherit;
    }

    @media print {

        .hidden-print,
        .hidden-print * {
            display: none !important;
        }


        .table {
            width: 100% !important;
            text-align: center;
            font-weight: bold;
        }
    }

    .centered {
        text-align: center;
        align-content: center;
    }

    @media print {
        .table {
            font-size: {{ $settings['PrintSize'] ?? 12 }}px !important;
        }

        td,
        th,
        tr,
        table {
            border: 1px solid black !important;
            border-collapse: collapse;
        }

        .table {
            border: 1px solid #020202 !important;
        }

        .table td,
        .table th {
            border: 1px solid #020202 !important;
            padding: 1px !important;
        }

        @page {
            size: 75mm auto;
            margin-top: 5px !important;
        }

        body {

            width: 75mm !important;
            margin: 0.5mm 0 0 0 !important;
            overflow: hidden;
        }

        .service-content {
            page-break-before: always;
        }

        html,
        body {
            /* width: 80mm;
            height: 100%; */
            margin: 0 !important;
            margin-right: 5px !important;
            padding: 0 !important;

        }
    }


</style>

<a class="btn print-window pull-right" href="{{ route('pos') }}" role="button">
    <i class="fa fa-backward" aria-hidden="true"></i> رجوع
</a>
<div class="ticket" style="max-width:68mm;" >
    <div class="service-content">
        <table class="table centered">
            <tr>
                <td colspan="2">

                    @if ($settings['logo'])
                        <div class="pull-right">
                            <img style="width: 110px" alt="Logo"
                                 src="{{ \Illuminate\Support\Facades\Storage::url($settings['logo']) }}
">
                        </div>
                    @endif
                    <div style="margin-bottom: 15px;" class="pull-left">
                        {!! $settings['SiteName'] !!}
                        @if ($settings['Address'])
                            <br />
                            {!! $settings['Address'] !!}
                        @endif
                        @if ($settings['mobile'])
                            <br />
                            {{ $settings['mobile'] }} <br>
                        @endif

                    </div>
                </td>
            </tr>
        </table>

        <table style="margin-top: 10px;" class="table table-bordered">
            <tr>
                <td style="font-weight: bold;font-size:18px!important;" colspan="2">فاتورة ضريبية مبسطة</td>
            </tr>
            <tr>
                <td>الفاتورة #</td>
                <td>{{ $order->invoice_number }}</td>
            </tr>
            <tr>
                <td>الدفع</td>
                <td>{{ $order->payment_type == 'delayed' ? 'أجل' : 'كاش' }}</td>
            </tr>
            <tr>
                <td>التاريخ</td>
                <td>{{ $order->invoice_date }}</td>
            </tr>
            <tr>
                <td>الكاشير</td>
                <td>{{ auth()->user()->name }}</td>
            </tr>
            <tr>
                <td>العميل</td>
                <td>{{ $order->client->name }}</td>
            </tr>
        </table>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th class="description">الوصف</th>
                <th class="price">السعر</th>
                <th class="price">إجمالى</th>
                <th>الموظف</th>
            </tr>
            </thead>
            <tbody>
            @php
                $numqty = 0;
                $sumprice = 0;
            @endphp
            @foreach ($order->items as $item)
                <tr>
                    @php
                        $numqty += $item->qty;
                        $sumprice += $item->total;
                        $tqty = $item->qty;
                        $product = optional($item->product);
                    @endphp
                    <td class="description">
                        {{ $product->full_name }}<br />
                        {{ $item->comment }}
                    </td>
                    <td class="price">
                        {{ currency($item->price, $order->currency, currency()->getUserCurrency(), $format = true) }}
                    </td>
                    <td>
                        {{ currency($item->total, $order->currency, currency()->getUserCurrency(), $format = true) }}
                    </td>
                    <td>{{ optional($item->employee)->name }}</td>
                </tr>
            @endforeach
            </tbody>
            <tfoot>
            <tr>
                <td>عدد الخدمات {{ $numqty }}</td>
                <td>الإجمالى</td>
                <td colspan="2">
                    {{ currency($sumprice, $order->currency, currency()->getUserCurrency(), $format = true) }}
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <table class="table">
                        <tr>
                            <td>الاجمالي قبل الضريبة</td>
                            <td>{{ currency($order->total - $order->tax_value, $order->currency, currency()->getUserCurrency(), $format = true) }}
                            </td>
                        </tr>
                        <tr>
                            <td>الضريبة</td>
                            <td>{{ $order->tax }}%</td>
                        </tr>
                        <tr>
                            <td>الخصم</td>
                            <td>
                                @php
                                    $discount = 0;
                                    $dist = $order->discount ?: 0;
                                    if ($order->discount) {
                                        if ($order->discount_type == 2) {
                                            $discount = $order->total * ($order->discount / 100);
                                            $dist = $discount;
                                            //$dist = "%".$order->discount. " ( $discount )";
                                        }
                                    }
                                    $totalafterDisc = $order->total - $dist;
                                @endphp
                                {{ currency($dist, $order->currency, currency()->getUserCurrency(), $format = true) }}
                            </td>
                        </tr>
                    </table>
                </td>
                <td colspan="2">
                    <table class="table">
                        <tr>
                            <td>المجموع</td>
                        </tr>
                        <tr>
                            <td>
                                {{ currency($totalafterDisc, $order->currency, currency()->getUserCurrency(), $format = true) }}
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="4">إجمالى المستحقات</td>
            </tr>
            <tr>
                <td colspan="4">
                    {{ currency($totalafterDisc, $order->currency, currency()->getUserCurrency(), $format = true) }}
                </td>
            </tr>
            @if ($order->client->total_due || $order->due)
                <tr>
                    <td colspan="4">
                        <table class="table">
                            <tr>
                                <td colspan="2">كشف حساب مختصر</td>
                            </tr>
                            <tr>
                                <td>المديونية السابقة</td>
                                <td>
                                    @php
                                        $total_due = $order->client->total_due;
                                    @endphp
                                    @if ($total_due)
                                        {{ currency($total_due - $order->due, $order->currency, currency()->getUserCurrency(), $format = true) }}
                                    @else
                                        0
                                    @endif
                                </td>
                            </tr>
                            <tr>
                                <td>الرصيد</td>
                                <td>{{ currency($total_due, $order->currency, currency()->getUserCurrency(), $format = true) }}
                                </td>
                            </tr>
                            @endif
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <p>
                            {!! $settings['InvoiceNotes'] !!}
                        </p>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        @php
                            $check = true;
                            try {
                                $Qcode = $order->generatQrcode(
                                    $settings['SiteName'],
                                    $settings['taxNumber'],
                                    $order->order_date,
                                    $order->total,
                                    $order->tax_value,
                                );
                            } catch (\Exception $e) {
                                $check = false;
                            }
                        @endphp
                        @if ($check)
                            <div style="margin-bottom: 5px;">
                                <img style="width: 100px;" src="{{ $Qcode }}">
                            </div>
                        @endif
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>
    @foreach ($order->items->groupBy('employee_id') as $employeeitems)
        <table class="table service-content">
            <tr>
                <td colspan="2">

                    @if ($settings['logo'])
                        <div class="pull-right">
                            <img style="width: 110px" alt="Logo"
                                 src="{{ \Illuminate\Support\Facades\Storage::url($settings['logo']) }}
    ">
                        </div>
                    @endif
                    <div style="margin-bottom: 15px;" class="pull-left">
                        {!! $settings['SiteName'] !!}
                        @if ($settings['Address'])
                            <br />
                            {!! $settings['Address'] !!}
                        @endif
                        @if ($settings['mobile'])
                            <br />
                            {{ $settings['mobile'] }} <br>
                        @endif

                    </div>
                </td>
            </tr>
            <tr>
                <td>الفاتورة #</td>
                <td>{{ $order->invoice_number }}</td>
            </tr>
            <tr>
                <td>العميل</td>
                <td>{{ $order->client->name }}</td>
            </tr>
            <tr>
                <td>الموظف</td>
                <td>{{ optional($item->employee)->name }}</td>
            </tr>
            @foreach ($employeeitems as $item)
                <tr>
                    <td>الخدمة {{ $loop->iteration }}</td>
                    <td>
                        @php
                            $serv = optional($item->product)->name;
                            $serv .= ' - '.date('Y-m-d h:i A', strtotime($item->serive_datetime));
                        @endphp
                        <p>{{ $serv }}</p>
                    </td>
                </tr>
            @endforeach

        </table>
    @endforeach
</div>
