<?php $__env->startSection('section-title', 'Return'); ?>
<?php $__env->startSection('page-title', 'Return Purchase List'); ?>

<?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 card-body card_style mb-2" style="margin-top: -3px" id="h-hide">
                <form action="<?php echo e(url('rtnPurchase')); ?>">
                    <div class="form-row">
                        <div class="form-group col-md-4">
                            <select class="select2" name="supplier_id">
                                <option selected value="">Select Supplier</option>
                                <?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supplier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($supplier->id); ?>"><?php echo e($supplier->name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="form-group col-md-4">
                            <input type="date" name="start_date" class="form-control" value="<?php echo e((isset($sdate))?date('Y-m-d', strtotime($sdate)):''); ?>">
                        </div>
                        <div class="form-group col-md-4">
                            <input type="date" name="end_date" class="form-control" value="<?php echo e((isset($edate))?date('Y-m-d', strtotime($edate)):''); ?>">
                        </div>
                    </div>
                    <div class="form-row mt-2">
                        <div class="form-group col-12">
                            <button class="btn add_list_btn" type="submit">
                                    <i class="fa fa-sliders"></i> Filter
                            </button>
                            <a href="<?php echo e(url('rtnPurchase')); ?>" 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>
            <div class="card m-b-30 card_style">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="datatable-buttons" class="table table-striped">
                            <thead class="header_bg">
                                <tr>
                                    <th class="header_style_left">#SL</th>
                                    <th>Date</th>
                                    <th>Purchase No</th>
                                    <th>Product</th>
                                    <th>Qty</th>
                                    <th>Biller</th>
                                    <th>Supplier</th>
                                    <th>Price</th>
                                    <th class="header_style_right">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $total_amt = 0;
                                ?>
                                <?php $__empty_1 = true; $__currentLoopData = $returns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=> $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <?php
                                        $returnItems= App\Models\ReturnPurchaseItem::where('rtnPurchase_id',$item->id)->get();
                                        // $product = App\Models\Product::where('id',$item->product_id)->first();
                                        $total_amt += $item->total_return;
                                    ?>
                                    <tr>
                                        <td class="table_data_style_left"><?php echo e($key+1); ?></td>
                                        <td><?php echo e(date('Y-m-d',strtotime($item->date))); ?></td>
                                        <td><?php echo e($item->purchase->purchase_no); ?></td>
                                        <td>
                                            <?php $__currentLoopData = $returnItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rtn): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <ul>
                                                    <li><?php echo e($rtn->product->name); ?></li>
                                                </ul>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $returnItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rtn): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <ul>
                                                    <li><?php echo e($rtn->main_qty); ?> </li>
                                                </ul>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td><?php echo e($item->user?->name); ?></td>
                                        <td><?php echo e($item->supplier->name); ?></td>
                                        <td><?php echo e($item->total_return); ?></td>
                                        <td class="table_data_style_right">
                                            <div class="dropdown">
                                                <button class="btn btn-dark btn-sm dropdown-toggle" type="button"
                                                    id="dropdownMenuButton" data-toggle="dropdown">
                                                    Action
                                                </button>
                                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                    <?php if(check_permission('purchase.destroy')): ?>
                                                        <a class="dropdown-item text-danger" href="#" data-toggle="modal"
                                                            data-target="#deleteModal-<?php echo e($item->id); ?>">
                                                            <i class="feather icon-trash"></i> Delete
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                            
                                            <form action="<?php echo e(route('return.purchase.delete', $item->id)); ?>" method="GET">
                                                <?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' => 'Return','id' => ''.e($item->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; ?>
                                                    
                                                    <input type="hidden" name="return_id" id="" value="<?php echo e($item->id); ?>">
                                            </form>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="100%" class="text-center text-danger no_data_style">No Data Available</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot>
                                <tr class="text-dark text-right footer_style">
                                    <td colspan="6" class="table_data_style_left text-white"><strong>Total: </strong></td>
                                    <td colspan="2" class="text-white"> <strong><?php echo e(number_format($total_amt,2)); ?> TK</strong></td>
                                    <td colspan="1" class="table_data_style_right"></td>
                                </tr>
                            </tfoot>
                        </table>
                        
                    </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>
        $(document).on('click', '.generated_barcode', function() {
            let name = $(this).attr('data-name');
            let code = $(this).attr('data-code');
            let price = $(this).attr('data-price');

            let pro_barcode = "<?php echo e(get_setting('pro_barcode')); ?>";

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

            $.get(url, (data) => {
                let company = "<?php echo e(config('app.name')); ?>";
                
                let barcode = '';
                if (pro_barcode == 'a4') {
                    barcode += `<div class="text-center p-4 print_area" id="barcode">
                        <table class="table table-bordered">`;
                            for ($i = 0; $i < 10; $i++) {
                                barcode += `<tr>`;

                                for ($j = 0; $j < 3; $j++) {
                                    barcode +=
                                    `<td>
                                        <p style="margin-bottom:2px; line-height:9px; margin-top:10px; font-size: 9px; color:black;"><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} 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="margin-bottom:2px; line-height:9px; margin-top:10px; font-size: 9px; color:black;"><strong>${company}</strong></p>

                                ${data}

                                <p style="margin-bottom:2px; line-height:9px; margin-top:2px; font-size: 9px; color:black;">${code}</p>

                                <p style="margin-bottom:2px; line-height:9px; margin-top:-2px; font-size: 9px; color:black;"><strong>${name}</strong></p>

                                <p style="margin-bottom:2px; line-height:9px; margin-top:0px; font-size: 12px; color:black;"><strong>${price} Tk</strong></p>
                                </td>
                            </tr>
                        </table>
                    </div>`;
                }

                $("#barcode-page").html(barcode);
            });

            $("#bar_code_modal").modal('show');
        });

    </script>

    <script>
        //  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();
            $(".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 /home/fastitco/organic-station.fastit.com.bd/resources/views/backend/pages/return/purchase/index.blade.php ENDPATH**/ ?>