<?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 add_list_btn">
            <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" style="margin: 0px 30px;margin-top: -25px;margin-bottom:70px;padding-top:10px">
                <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 add_list_btn">Filter</button>
                                <a href="<?php echo e(route('purchase.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="table-responsive mt-3">
                        <table id="datatable-buttons" class="table text-white table-striped">
                            <thead class="" style="background: #000ce2;border:none">
                                <tr class="text-center">
                                    <th class="header_style_left"> 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 class="header_style_right"> 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, 
                                        )->first();
                                        $purchase_items = App\Models\PurchaseItem::where(
                                            'purchase_id',
                                            $data->id, 
                                        )->get();
                                    ?>
                                    <tr class="text-center">
                                        <td class="table_data_style_left"><?php echo e($data->date); ?></td>
                                        <td><?php echo e($data->purchase_no); ?></td>
                                        
                                            <td>
                                                <?php $__currentLoopData = $purchase_items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <ul>
                                                        <li>
                                                            <?php echo e($item->product?->name); ?> <?php if(env('APP_SC') == 'yes'): ?>  (<?php echo e($item->product_variation?->size?->size); ?>-<?php echo e($item->product_variation?->color?->color); ?>) <?php endif; ?>
                                                        </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 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('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; ?>
                                                    <?php if(env('APP_IMEI') == 'yes'): ?>
                                                        
                                                        <a class="dropdown-item text-success" href="<?php echo e(route('purchase.imei-print', $data->id)); ?>">
                                                            <i class="feather icon-printer"></i> Print
                                                        </a>
                                                    <?php else: ?>
                                                        
                                                        <a class="dropdown-item text-success" href="<?php echo e(route('purchase.print', $data->id)); ?>">
                                                            <i class="feather icon-printer"></i> Print
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    <?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 text-danger no_data_style">No Purchase Found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot class="">
                                <tr class=" text-right text-white"  style="background: #000ce2;color:white;border-radius:25px">
                                    <td colspan="5" style="border-radius: 25px 0 0 25px; padding: 10px; background: #000ce2;color:white"><strong>Total: </strong></td>
                                    <td> <strong class="text-white"><?php echo e(number_format($total_amt,2)); ?> </strong></td>
                                    <td> <strong class="text-white"><?php echo e(number_format($total_paid,2)); ?></strong></td>
                                    <td> <strong class="text-white"><?php echo e(number_format($total_due,2)); ?></strong></td>
                                    <td colspan="3" style="border-radius: 0 25px 25px 0; padding: 10px; background: #000ce2;"></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 /home/fastitco/nvs.fastit.com.bd/resources/views/backend/pages/purchase/index.blade.php ENDPATH**/ ?>