<style>
        @page {
        margin: 0;
        }
        @media print {
            .no-screen{
                display: none !important;
            }  
        }
        .receipt {
            width: 78mm;
            font-size: 12px;
            padding: 12px;
            border: 1px solid #ccc;
        }

        .receipt h1 {
            font-size: 16px;
            font-weight: bold;
            margin-top: 0;
        }

        .receipt p {
            margin: 0;
        }

        .receipt table {
            width: 100%;
            border-collapse: collapse;
        }

        .receipt .header-table {
            width: 100%;
            border-collapse: collapse;
            line-height:4px;
        }

        .receipt th,
        .receipt td {
            padding: 5px;
            text-align: left;
        }

        .receipt th {
            background-color: #f2f2f2;
        }

        .receipt .total p,
        .receipt .price p {
            font-size: 12px;
            font-weight: bold;
        }

        .image {
            display: flex;
            justify-content: center;
        }

        .image img {
            width: 100px;
            object-fit: cover;
        }
    </style>

<?php if(isset($type)): ?>
<div class="receipt">
    <div class="image">
        <img src="<?php echo e(isset($business_details) && isset($business_details->logo) ? url( 'storage/business_logos/' . $business_details->logo)  : asset('img/logo.png')); ?>" alt="" width="250px" height="100px">
    </div>
    <h1 style="text-align: center;"><?php echo e(isset($business_details) && isset($business_details->name) ? $business_details->name :'GDS - RESTAURANT'); ?></h1>
    <!--<p class="text-center">(Tourist Board Approved)</p>-->
    <p style="text-align: center;"><?php echo e(isset($business_details) && isset($business_details->address) ? $business_details->address :'NO-603, HOSPITAL ROAD,'); ?> <?php echo e(isset($business_details) && isset($business_details->city) ? $business_details->city :'Colombo'); ?></p>
    <p style="text-align: center;"><?php echo e(isset($business_details) && isset($business_details->mobile) ? $business_details->mobile :' '); ?>, <?php echo e(isset($business_details) && isset($business_details->phone) ? $business_details->phone :' '); ?></p>
    <p style="text-align: center;"><?php echo e(isset($business_details) && isset($business_details->email) ? $business_details->email :'admin@gmail.com'); ?></p>
    <br>
    <?php
    $order_type = '';
            if($transaction->room_id && $transaction->order_type == 'Room Order')
            {
                $room_get =  App\Models\RoomAssign::find($transaction->room_id);
                $order_type = $transaction->order_type .'(' .$room_get->room_id. ')';
            }
            if($transaction->table_id && $transaction->order_type == 'Dine in')
            {
                $table =  App\Models\Table::find($transaction->table_id);
                $order_type = $transaction->order_type .'(' .$table->table_name. ')';
            }
            if($transaction->order_type == 'Take away')
            {
                $order_type = $transaction->order_type;
            }
            if($transaction->order_type == 'Online')
            {
                $order_type = $transaction->order_type;
            }
    ?>
    <div class="grid grid-cols-1">
        <table class="header-table">
            <tr>
                <td>IN No.: <?php echo e($transaction->invoice_no ?? ''); ?></td>
                <td>Date: <?php echo e($transaction->created_at ?? ''); ?></td>
            <tr>
            <tr>
                <!-- <td>OD No.: <?php echo e($transaction->lines_of_sell->first() ? $transaction->lines_of_sell->first()->order_no : ''); ?></td> -->
                <td>OT: <?php echo e($order_type); ?></td>
                <td>User: <?php echo e($transaction->staff->first_name ?? ''); ?></td>
            <tr>
            <tr>
                <td colspan="2">Customer: <?php echo e($transaction->customer->first_name ?? ''); ?></td>
            <tr>
            <!-- <tr>
                <td  colspan="2">Waiter: <?php echo e($transaction->staff->first_name ?? ''); ?></td>
            <tr>    -->
        </table>
    </div>
    <div class="grid grid-cols-1">
    <p class="text-end"></p>
    </div>
    <table style="margin: 10px 0;">
        <thead>
            <tr>
                <td>No</td>
                <td>Item</td>
                <td style="text-align: right;">Amt</td>
            </tr>
        </thead>
        <tbody style="border-top: 1px dotted black">
            <?php
                $no = 1;
            ?>
            <?php $__currentLoopData = $transaction->lines_of_sell; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $line): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td><?php echo e($no++); ?></td>
                <td style="width: 70%;"><?php echo e($line->product->name ?? ''); ?>  <?php echo e($line->product->sku_code ?? ''); ?>

                    
                    <span><?php echo e($line->quantity ?? 0); ?>x<?php echo e($line->unit_price ?? '0.00'); ?></span>
                    <?php if($line->discount_amount > 0): ?>
                    <br>
                    <span>Discount: <?php echo e(number_format($line->discount_amount, 2)); ?></span>
                    <?php endif; ?>
                </td>
                <td style="width: 30%; text-align: right;"><?php echo e($line->sub_total ?? '0.00'); ?></td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>
    <div class="grid grid-cols-1">
        <?php 
        $payments = App\Models\TransactionPayment::where('transaction_id', $transaction->id);
        $payment = $payments->first();
        $paid = $payments->sum('customer_paid');
        $due = $transaction->final_total - $paid;
        $tax = $transaction->tax_amount > 0 ? ($transaction->tax_amount /100) * $transaction->lines_of_sell->sum('sub_total') : 0;
        ?>
        <table style="right: 2px;line-height:5px;">
            <tr  style="border-top: 1px dotted black;line-height:1;">
                <td style="text-align:left;font-size:14px;">Sub Total:</td>
                <td style="text-align:right"><?php echo e(number_format($transaction->lines_of_sell->sum('sub_total'), 2)); ?></td>
            </tr>
            <!-- <tr>
                <td style="text-align:left">Sevice Charge : </td>
                <td style="text-align:right"><?php echo e($transaction->service_charge); ?></td>
            </tr> -->
            <tr>
                <td style="text-align:left">Tax : </td>
                <td style="text-align:right"><?php echo e($tax > 0 ? number_format($tax, 2) : '0.00'); ?></td>
            </tr>
            <tr>
                <td style="text-align:left">Discount : </td>
                <td style="text-align:right"><?php echo e($transaction->discount_amount > 0 ? number_format($transaction->discount_amount, 2) : '0.00'); ?></td>
            </tr>
            <tr  style="border-top: 1px dotted black;line-height:1;">
                <td style="text-align:left;font-size:14px;"><strong>Total:</strong></td>
                <td style="text-align:right;font-size:14px;"><strong><?php echo e($transaction->lines_of_sell->sum('sub_total') > 0 ? number_format($transaction->lines_of_sell->sum('sub_total'), 2) : '0.00'); ?></strong></td>
            </tr>
            <tr  style="border-top: 1px dotted black;">
                <td style="text-align:left">Total Items:</td>
                <td style="text-align:right"><?php echo e($transaction->lines_of_sell->sum('quantity')); ?></td>
            </tr>
            <?php if(isset($payment)): ?>
            <tr>
                <td style="text-align:left"><?php echo e($payment->method); ?>: </td>
                <td style="text-align:right"><?php echo e($payment->amount > 0 ? number_format($payment->customer_paid, 2) : '0.00'); ?></td>
            </tr>
            <?php endif; ?>
            <tr>
                <td style="text-align:left">Balance:</td>
                <td style="text-align:right"><?php echo e($due < 0 ? number_format(str_replace('-', '', $due), 2) : '0.00'); ?></td>
            </tr>
        </table>  
    </div>
    <p  style="line-height: 12px; margin-top: 10px; font-size: 16px;text-align: center;"><b>No Service Charges</b></p>
    <br>
    <div class="barcode" style="display: flex; justify-content: center;">
        <img class="center-block" src="data:image/png;base64,<?php echo e(DNS1D::getBarcodePNG($transaction->invoice_no, 'C128', 2,30,array(39, 48, 54), true)); ?>" width="200px" height="100px">
    </div>
    <p  style="line-height: 12px; margin-top: 10px; font-size: 9px;text-align: center;">Thank you come again
    </p>
    <div>
        <span style="font-size: 7px; display: flex; justify-content: center; margin-top: 20px;">Software by 
            Loopdigi - +94768271573</span>
    </div>
</div>
<?php else: ?>

<?php if($business_details->printer_display == 'DirectPrint'): ?>
    <?php
        $order_type = '';
        if($transaction->room_id && $transaction->order_type == 'Room Order') {
            $room_get =  App\Models\RoomAssign::find($transaction->room_id);
            $order_type = $transaction->order_type .'(' .$room_get->room_id. ')';
        }
        if($transaction->table_id && $transaction->order_type == 'Dine in') {
            $table =  App\Models\Table::find($transaction->table_id);
            $order_type = $transaction->order_type .'(' .$table->table_name. ')';
        }
        if($transaction->order_type == 'Take away') {
            $order_type = $transaction->order_type;
        }
        if($transaction->order_type == 'Online') {
            $order_type = $transaction->order_type;
        }
    ?>

    
    <?php if(collect($products ?? [])->contains(function ($product) use ($transaction) {
        $line = App\Models\TransactionSellLine::where('transaction_id', $transaction->id)
            ->where('product_id', $product['product_id'])->first();
        return $line && $line->product->is_kot == 1;
    })): ?>
        <div class="receipt">
            <h1 class="text-center" style="font-size: 18px; font-weight: bold; margin-bottom: 10px;">KOT</h1>
            <h3 class="text-center" style="font-size: 14px; font-weight: bold; margin-bottom: 10px;"><?php echo e($order_type); ?></h3>

            <div class="grid grid-cols-1">
                <table class="header-table"  style="font-size: 12px;">
                    <tr>
                        <td>IN No.: <?php echo e($transaction->invoice_no ?? ''); ?></td>
                        <td><?php echo e(date('Y-m-d H:i:s A')); ?></td>
                    <tr>
                    <tr>
                        <!-- <td>OD No.: <?php echo e($transaction->lines_of_sell->first() ? $transaction->lines_of_sell->first()->order_no : ''); ?></td> -->
                        <td colspan="2">Customer: <?php echo e($transaction->customer->first_name ?? ''); ?></td>
                    <tr>
                    <tr>
                        <td  colspan="2">User: <?php echo e($transaction->staff->first_name ?? ''); ?></td>
                    <tr>   
                </table>
            </div>

            <table style="margin: 10px 0;font-size: 18px;">
                <thead>
                    <tr>
                        <td>No</td>
                        <td>Item</td>
                        <td>Qty</td>
                    </tr>
                </thead>
                <tbody style="border-top: 1px solid lightgray;">
                    <?php 
                        $total_qty = 0;
                        $no = 1;
                    ?>
                    <?php $__currentLoopData = $products ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php 
                            $line = App\Models\TransactionSellLine::where('transaction_id', $transaction->id)
                                ->where('product_id',$product['product_id'])->first(); 
                        ?>
                        <?php if($line && $line->product->is_kot == 1): ?>
                            <?php $total_qty += $product['quantity']; ?>
                            <tr>
                                <td><?php echo e($no++); ?></td>
                                <td style="width: 70%;"><?php echo e($line->product->name ?? ''); ?> <?php echo e($line->product->sku_code ?? ''); ?></td>
                                <td style="width: 10%; text-align: right;"><?php echo e($product['quantity']); ?></td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>

            <div style="display: flex; justify-content: flex-end; gap: 50px; margin-right: 5px; border-top: 1px solid lightgray; font-size: 14px; font-weight: bold; padding-top: 6px;">
                <p>Total Items: </p>
                <p class="text-end"><?php echo e($total_qty); ?></p>
            </div>
            <div>
                <span style="font-size: 7px; display: flex; justify-content: center; margin-top: 20px;">Created by Loopdigi - +94768271573</span>
            </div>
        </div>
    <?php endif; ?>

    
    <?php if(collect($products ?? [])->contains(function ($product) use ($transaction) {
        $line = App\Models\TransactionSellLine::where('transaction_id', $transaction->id)
            ->where('product_id', $product['product_id'])->first();
        return $line && $line->product->is_bot == 1;
    })): ?>
        <div class="receipt">
            <h1 class="text-center" style="font-size: 18px; font-weight: bold; margin-bottom: 10px;">BOT</h1>
            <h3 class="text-center" style="font-size: 14px; font-weight: bold; margin-bottom: 10px;"><?php echo e($order_type); ?></h3>

            <div class="grid grid-cols-1">
                <table class="header-table"  style="font-size: 12px;">
                    <tr>
                        <td>IN No.: <?php echo e($transaction->invoice_no ?? ''); ?></td>
                        <td><?php echo e(date('Y-m-d H:i:s A')); ?></td>
                    <tr>
                    <tr>
                        <!-- <td>OD No.: <?php echo e($transaction->lines_of_sell->first() ? $transaction->lines_of_sell->first()->order_no : ''); ?></td> -->
                        <td colspan="2">Customer: <?php echo e($transaction->customer->first_name ?? ''); ?></td>
                    <tr>
                    <tr>
                        <td  colspan="2">User: <?php echo e($transaction->staff->first_name ?? ''); ?></td>
                    <tr>   
                </table>
            </div>

            <table style="margin: 10px 0;font-size: 18px;">
                <thead>
                    <tr>
                        <td>No</td>
                        <td>Item</td>
                        <td>Qty</td>
                    </tr>
                </thead>
                <tbody style="border-top: 1px solid lightgray;">
                    <?php 
                        $total_qty = 0; 
                        $no = 1;
                    ?>
                    <?php $__currentLoopData = $products ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php 
                            $line = App\Models\TransactionSellLine::where('transaction_id', $transaction->id)
                                ->where('product_id',$product['product_id'])->first(); 
                        ?>
                        <?php if($line && $line->product->is_bot == 1): ?>
                            <?php $total_qty += $product['quantity']; ?>
                            <tr>
                                <td><?php echo e($no++); ?></td>
                                <td style="width: 70%;"><?php echo e($line->product->name ?? ''); ?>  <?php echo e($line->product->sku_code ?? ''); ?></td>
                                <td style="width: 10%; text-align: right;"><?php echo e($product['quantity']); ?></td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>

            <div style="display: flex; justify-content: flex-end; gap: 50px; margin-right: 5px; border-top: 1px solid lightgray; font-size: 14px; font-weight: bold; padding-top: 6px;">
                <p>Total Items: </p>
                <p class="text-end"><?php echo e($total_qty); ?></p>
            </div>
            <div>
                <span style="font-size: 7px; display: flex; justify-content: center; margin-top: 20px;">Created by Loopdigi - +94768271573</span>
            </div>
        </div>
    <?php endif; ?>
<?php endif; ?>

<?php endif; ?>
                <?php /**PATH /home/loopdigim/public_html/sabari_hotel/resources/views/pos/receipt/receipt.blade.php ENDPATH**/ ?>