<?php $__env->startSection('section-title', 'Product'); ?>
<?php $__env->startSection('page-title', 'Product List'); ?>
<?php if(check_permission('product.create')): ?>
    <?php $__env->startSection('action-button'); ?>
        <a href="<?php echo e(route('product.create')); ?>" class="btn add_list_btn">
            <i class="mr-2 feather icon-plus"></i>
            Add Product
        </a>
    <?php $__env->stopSection(); ?>
<?php endif; ?>
<?php $__env->startPush('css'); ?>
<style>
    @media print {
        @page {
        size: auto;
        }

        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            font-family: Roboto,sans-serif;
        }

        .print_area {
            position: absolute;
            top: 0;
            width: 100%;
        }

        .print_area * {
            visibility: visible !important;
        }
    }
</style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card m-b-30 card_style">
                <div class="card-body">
                    <form action="<?php echo e(route('product.index')); ?>" method="GET">
                        <?php
                            $categories = App\Models\Category::get();
                            $produc = App\Models\Product::where('is_service',0)->get();
                        ?>
                        <div class="row">
                            
                            <div class="col-md-3 mt-3">
                                <input type="text" class="form-control" name="barcode" placeholder="Enter Barcode" value="<?php echo e($barcode); ?>" />
                            </div>
                            
                            <div class="col-md-3 mt-3">
                                <select name="product_id" id="" class="select2">
                                    <option value="">All Product</option>
                                    <?php $__currentLoopData = $produc; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($item->id); ?>"<?php echo e(($product_id == $item->id)?'selected' : ''); ?>><?php echo e($item->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-3 mt-3">
                                <select name="category_id" id="" class="select2">
                                    <option value="">All Category</option>
                                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($item->id); ?>"<?php echo e(($category_id == $item->id)?'selected' : ''); ?>><?php echo e($item->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-3 mt-3">
                                <button type="submit" class="btn add_list_btn">Filter</button>
                                <a href="<?php echo e(route('product.index')); ?>" class="btn add_list_btn_reset">Reset</a>
                                <a href="" class="btn add_list_btn float-right" onclick="window.print()">Print</a>
                            </div>
                        </div>
                    </form>
                    <div class="row mt-2" style="background: #f2f2f2;padding-top: 3px">
                        <div class="col-md-12 text-right">
                            <?php 
                            $total_product = App\Models\Product::where('is_service',0)->count();
                            ?>
                            <h5><strong>Total Product : <?php echo e($total_product); ?> </strong> </h5>
                            
                        </div>
                    </div>
                    <div class="table-responsive mt-3">
                        <table id="datatable-buttons" class="table table-striped">
                            <thead class="header_bg">
                                <tr>
                                    <th class="header_style_left">#SL</th>
                                    <th>Name</th>
                                    <th>Barcode</th>
                                    <th>Category</th>
                                    <th>Brand</th>
                                    <th>Cost</th>
                                    <th>Price</th>
                                    <th>Status</th>
                                    <th></th>
                                    <th class="header_style_right">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <?php
                                        $count_inv = App\Models\InvoiceItem::where('product_id', $data->id)->count();
                                        $count_pur = App\Models\PurchaseItem::where('product_id', $data->id)->count();
                                        
                                    ?>
                                    <tr>
                                        <td class="table_data_style_left"><?php echo e($loop->index + 1); ?></td>
                                        <td><?php echo e($data->name); ?></td>
                                        <td><?php echo e($data->barcode); ?></td>
                                        <td><?php echo e($data->category->name); ?></td>
                                        <td><?php echo e(($data->brand_id==NULL)?"No Brand":$data->brand->name); ?></td>
                                        <td><?php echo e($data->purchase_price); ?></td>
                                        <td><?php echo e($data->selling_price); ?></td>
                                        <td>
                                            <?php if($data->status == 1 ): ?>
                                                Active
                                            <?php endif; ?>
                                            <?php if($data->status == 0): ?>
                                                Deactive
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <a href="#" class="btn btn-primary-rgba generated_barcode"
                                                data-name="<?php echo e($data->name); ?>" data-code="<?php echo e($data->barcode); ?>"
                                                data-price="<?php echo e($data->selling_price); ?>">
                                                <i class="fa fa-barcode"></i>
                                            </a>
                                        </td>
                                        <td class="table_data_style_right">
                                            <div class="dropdown">
                                                <button class="btn add_list_btn btn-sm dropdown-toggle" type="button"
                                                    id="dropdownMenuButton" data-toggle="dropdown">
                                                    Action
                                                </button>
                                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                    <?php if(check_permission('product.edit')): ?>
                                                        <a href="<?php echo e(route('product.edit', $data->id)); ?>"
                                                            class="dropdown-item text-primary">
                                                            <i class="feather icon-edit"></i> Edit
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    <?php if(check_permission('product.destroy')): ?>
                                                        <?php if($count_inv<1 && $count_pur<1): ?>
                                                            <a href="#" data-toggle="modal"
                                                                data-target="#deleteModal-<?php echo e($data->id); ?>"
                                                                class="dropdown-item text-danger <?php echo e($data->id == 1 ? 'disabled' : ''); ?>">
                                                                <i class="feather icon-trash"></i> Delete
                                                            </a>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>

                                    
                                    <form action="<?php echo e(route('product.destroy', $data->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <?php if (isset($component)) { $__componentOriginal37b7f052626c638ba0443fdb400d6f57 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal37b7f052626c638ba0443fdb400d6f57 = $attributes; } ?>
<?php $component = App\View\Components\DeleteModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('delete-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(App\View\Components\DeleteModal::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Product','id' => ''.e($data->id).'']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal37b7f052626c638ba0443fdb400d6f57)): ?>
<?php $attributes = $__attributesOriginal37b7f052626c638ba0443fdb400d6f57; ?>
<?php unset($__attributesOriginal37b7f052626c638ba0443fdb400d6f57); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal37b7f052626c638ba0443fdb400d6f57)): ?>
<?php $component = $__componentOriginal37b7f052626c638ba0443fdb400d6f57; ?>
<?php unset($__componentOriginal37b7f052626c638ba0443fdb400d6f57); ?>
<?php endif; ?>
                                    </form>

                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="100%" class="text-center no_data_style text-danger">No Data Available</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                        <?php echo e($products->onEachSide(1)->links()); ?>

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

    <div class="modal fade" id="bar_code_modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-body" id="barcode-page">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-success delete" onclick="print_barcode()"><i class="fa fa-print"></i>
                        Print</button>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
<script>
    function setFilterType($this) {
        var filterType = $($this).val();
        $('.generated_barcode').attr('data-size', filterType);
    }

    $(document).on('click', '#modal_cancel', function() {
        $("#bar_code_modal").modal('hide');
        $('.generated_barcode').attr('data-size', '');
    });

    $(document).on('click', '.generated_barcode', function() {
        let name = $(this).attr('data-name');
        let code = $(this).attr('data-code');
        let price = $(this).attr('data-price');
        var variation = $(this).attr('data-size');
        let pro_barcode = "<?php echo e(get_setting('pro_barcode')); ?>";

        // Convert price to formatted string with commas and decimals
        const formattedPrice = new Intl.NumberFormat('en-US', {
            useGrouping: true,
            // style: 'currency',
            // currency: 'USD', // Change to your desired currency if needed
            minimumFractionDigits: 2
        }).format(price);

        let url = "<?php echo e(route('product-barcode', 'value')); ?>".replace('value', code);

        $.get(url, (data) => {
            let company = "<?php echo e($com->value); ?>";

            let barcode = '';
            if (pro_barcode == 'a4') {
                barcode += `<div class="text-center p-4 print_area" id="barcode">
                    <table class="table table-bordered">`;
                        for (let i = 0; i < 10; i++) {
                            barcode += `<tr>`;
                            for (let j = 0; j < 3; j++) {
                                barcode +=
                                `<td>
                                    <p style="margin-bottom:2px; line-height:9px; margin-top:5px; font-size: 15px; color:black;text-transform:uppercase;!important"><strong>${company}</strong></p>
                                    ${data}
                                    <p style="margin-bottom:2px; line-height:9px; margin-top:3px; font-size: 9px; color:black;"><strong>${name}</strong></p>
                                    <p style="margin-bottom:2px; line-height:9px; margin-top:3px; font-size: 9px; color:black;"><strong> Price: ${formattedPrice} Tk</strong></p>
                                </td>`;
                            }
                            barcode += `</tr>`;
                        }
                    barcode += `
                    </table>
                </div>`;
            } else if (pro_barcode == 'single') {
                barcode += `<div class="text-center p-4 print_area" id="barcode" style="padding:0 !important">
                    <table class="table" style="margin-bottom:0 !important;">
                        <tr>
                            <td style="border-top:0 !important;padding:0;">
                            <p style="font-family: Arial, sans-serif;line-height:9px;margin-bottom:2px; font-size: 13px;margin-top:12px; font-weight: 500; text-transform: uppercase;  color: black;"><strong>${company}</strong></p>
                            ${data}
                            <p style="margin-bottom:0px; line-height:9px; margin-top:2px; font-size: 6px; color:black;"><strong>${code}</strong></p>
                            <p style="margin-bottom:2px; line-height:9px; margin-top:0px; font-size: 9px; color:black;"><strong>${name}</strong></p>
                            <p style="margin-bottom:2px; line-height:9px; margin-top:5px; font-size: 12px; color:black;"><strong>Price: ${formattedPrice}</strong></p>
                            </td>
                        </tr>
                    </table>
                </div>`;
            }
            $("#barcode-page").html(barcode);
        });
        $("#bar_code_modal").modal('show');
    });
</script>


    <script>
        //  Print Barcode
        //  Print Barcode
        function print_barcode(id) {
            $("#bar_code_modal").modal('hide');
            $(".modal-backdrop").remove();
            $(".modal").css('display', 'none');

            let mainDocBody = $('.main-container').html();
            let printDoc = $("#barcode-page").html();
            $(".main-container").html(printDoc);
            $("body").attr('style', '');
            window.print();
            window.location.reload();
            $(".main-container").html(mainDocBody);
    }
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\new demo multi-bank\resources\views/backend/pages/product/index.blade.php ENDPATH**/ ?>