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

            table,
            table th,
            table td {
                color: black !important;
            }

            .h-hide {
                display: none;
            }
        }
    </style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card m-b-30">
                <div class="card-body">
                    <form action="<?php echo e(route('purchase.index')); ?>" method="GET">
                        <?php
                            $suppliers = App\Models\Supplier::get();
                            $products = App\Models\Product::get();
                        ?>
                        <div class="row h-hide">
                            <div class="col-md-3 mt-2">
                                <input type="date" class="form-control" name="startDate" value="<?php echo e($startDate); ?>" />
                            </div>
                            <div class="col-md-3 mt-2">
                                <input type="date" class="form-control" name="endDate" value="<?php echo e($endDate); ?>" />
                            </div>
                            <div class="col-md-3 mt-2">
                                <input type="text" placeholder="Enter Purchase No" value="<?php echo e($purchase_no); ?>"
                                    name="purchase_no" class="form-control">
                            </div>
                            <div class="col-md-3 col-12 mt-2">
                                <select name="product_id" id="" class="select2">
                                    <option value="">Select Product</option>
                                    <?php $__currentLoopData = $products; $__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-2">
                                <select name="supplier_id" id="" class="select2">
                                    <option value="">Select Supplier</option>
                                    <?php $__currentLoopData = $suppliers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option
                                            value="<?php echo e($item->id); ?>"<?php echo e($supplier_id == $item->id ? 'selected' : ''); ?>>
                                            <?php echo e($item->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="row mt-3 h-hide d-flex justify-content-between">
                            <div class="col-md-12 col-12">
                                <button type="submit" class="btn btn-primary">Filter</button>
                                <a href="<?php echo e(route('purchase.index')); ?>" class="btn btn-primary">Reset</a>
                                <a href="" class="btn btn-primary float-right" onclick="window.print()">Print</a>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive mt-3">
                        <table id="datatable-buttons" class="table table-striped table-bordered">
                            <thead class="table-primary">
                                <tr class="text-center">
                                    <th> Purchase Date </th>
                                    <th> Purchase No </th>
                                    <th> Product </th>
                                    <th> Supplier </th>
                                    <th> Creator </th>
                                    <th> Total Amount </th>
                                    <th> Total Paid </th>
                                    <th> Total Due </th>
                                    <th> Status </th>
                                    <th> Action </th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $total_paid = 0;
                                    $total_amt = 0;
                                    $total_due = 0;
                                ?>
                                <?php $__empty_1 = true; $__currentLoopData = $purchases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <?php
                                        $total_paid += $data->total_paid;
                                        $total_amt += $data->total_amount;
                                        $total_due += $data->total_due;
                                        $purchase_item = App\Models\PurchaseItem::where(
                                            'purchase_id',
                                            $data->id,
                                        )->get();
                                    ?>
                                    <tr class="text-center">
                                        <td><?php echo e($data->date); ?></td>
                                        <td><?php echo e($data->purchase_no); ?></td>
                                        
                                        <td>
                                            <?php $__currentLoopData = $purchase_item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <ul>
                                                    <li>
                                                        <?php echo e($item->product->name); ?>

                                                    </li>
                                                </ul>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td><?php echo e($data->supplier->name); ?></td>
                                        <td><?php echo e($data->user->name); ?></td>
                                        <td><?php echo e($data->total_amount); ?></td>
                                        <td><?php echo e($data->total_paid); ?></td>
                                        <td><?php echo e($data->total_due); ?></td>
                                        <td>
                                            <?php if($data->status == 0): ?>
                                                <span class="badge badge-warning">Due</span>
                                            <?php elseif($data->status == 1): ?>
                                                <span class="badge badge-success">Paid</span>
                                            <?php elseif($data->status == 2): ?>
                                                <span class="badge badge-danger">Returned</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <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.pay')): ?>
                                                        <?php if($data->total_due > 0): ?>
                                                            <a class="dropdown-item text-success" href="<?php echo e(url('purchase/pay/' . $data->id)); ?>">
                                                                <i class="feather icon-dollar-sign"></i> Due
                                                            </a>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                    <?php if(check_permission('rtnPurchase.edit')): ?>
                                                        <a class="dropdown-item text-warning" href="<?php echo e(route('rtnPurchase.edit',$data->id)); ?>">
                                                            <i class="fa fa-undo"></i> Return
                                                        </a>
                                                    <?php endif; ?>
                                                    <?php if(check_permission('purchase.edit')): ?>
                                                        <a class="dropdown-item text-info" href="<?php echo e(url('purchase/edit/' . $data->id)); ?>">
                                                            <i class="fa fa-edit"></i> Edit
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    <a class="dropdown-item text-success" href="<?php echo e(route('purchase.print', $data->id)); ?>">
                                                        <i class="feather icon-printer"></i> Print
                                                    </a>

                                                    
                                                    <?php if(check_permission('purchase.destroy')): ?>
                                                        <a class="dropdown-item text-danger" href="#" data-toggle="modal"
                                                            data-target="#deleteModal-<?php echo e($data->id); ?>">
                                                            <i class="feather icon-trash"></i> Delete
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>

                                    
                                    <form action="<?php echo e(route('purchase.destroy', $data->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <?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' => 'Purchase','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="12" class="text-center">No Purchase Found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot class="text-dark">
                                <tr class="text-dark text-right">
                                    <td colspan="5"><strong>Total: </strong></td>
                                    <td> <strong><?php echo e(number_format($total_amt,2)); ?> TK</strong></td>
                                    <td> <strong><?php echo e(number_format($total_paid,2)); ?> TK</strong></td>
                                    <td> <strong><?php echo e(number_format($total_due,2)); ?> TK</strong></td>
                                    <td colspan="3"></td>
                                </tr>
                            </tfoot>
                        </table>
                        <?php echo e($purchases->onEachSide(1)->links()); ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

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