<?php $__env->startSection('section-title', 'Invoice'); ?>
<?php $__env->startSection('page-title', 'Invoice List'); ?>
<?php if(check_permission('invoice.create')): ?>
    <?php $__env->startSection('action-button'); ?>
        <a href="<?php echo e(route('invoice.create')); ?>" class="btn add_list_btn">
            <i class="mr-2 feather icon-plus"></i>
            Add Invoice
        </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 card_style">
                <div class="card-body">
                    <form action="<?php echo e(route('invoice.index')); ?>" method="GET">
                        <?php
                            $customers = App\Models\Customer::get();
                            $products = App\Models\Product::get();
                        ?>
                        <div class="row h-hide">
                            <div class="col-md-3 col-12 mt-3">
                                <input type="date" class="form-control" name="startDate" value="<?php echo e($startDate); ?>" />
                            </div>
                            <div class="col-md-3 col-12 mt-3">
                                <input type="date" class="form-control" name="endDate" value="<?php echo e($endDate); ?>" />
                            </div>
                            <div class="col-md-3 col-12 mt-3">
                                <input type="text" placeholder="Enter Invoice No" name="invoice_no"
                                    value="<?php echo e($invoice_no); ?>" class="form-control">
                            </div>
                            <div class="col-md-3 col-12 mt-3">
                                <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 col-12 mt-3">
                                <select name="customer_id" id="" class="select2">
                                    <option value="">Select Customer</option>
                                    <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option
                                            value="<?php echo e($item->id); ?>"<?php echo e($customer_id == $item->id ? 'selected' : ''); ?>>
                                            <?php echo e($item->name); ?> <?php echo e($item->phone); ?></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">
                                <button type="submit" class="btn add_list_btn">Filter</button>
                                <a href="<?php echo e(route('invoice.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-2">
                        <table id="datatable-buttons" class="table table-striped table-bordered">
                            <thead class="header_bg">
                                <tr class="text-center">
                                    <th class="header_style_left"> SL# </th>
                                    <th> Date </th>
                                    <th> Invoice No </th>
                                    <th> Customer </th>
                                    <th> Product Item(s) </th>
                                    <th> Total Amount </th>
                                    <th> Total Paid </th>
                                    <th> Total Due </th>
                                    <th> Return Amount </th>
                                    <th> Status </th>
                                    <th> Create By </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 = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $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;
                                    $inv_items = App\Models\InvoiceItem::where('invoice_id',$data->id)->get();
                                ?>
                                    <tr class="text-center">
                                        <td class="table_data_style_left"><?php echo e($key + 1); ?></td>
                                        <td><?php echo e($data->date); ?></td>
                                        <td><?php echo e($data->invoice_no); ?></td>
                                        <td><?php echo e($data->customer->name); ?></td>
                                        <td>
                                            <?php $__currentLoopData = $inv_items; $__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->total_amount); ?></td>
                                        <td><?php echo e($data->total_paid); ?></td>
                                        <td><?php echo e($data->total_due); ?></td>
                                        <td>
                                            <?php if($data->return_amount == null): ?>
                                                    0.00
                                            <?php else: ?>
                                                <?php echo e($data->return_amount); ?>

                                            <?php endif; ?>
                                            </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><?php echo e($data->user->name); ?></td>
                                        <td class="table_data_style_right">
                                            <div class="dropdown">
                                                <button class="btn btn-secondary btn-sm dropdown-toggle" type="button"
                                                    id="dropdownMenuButton" data-toggle="dropdown" >
                                                    Action
                                                </button>
                                                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                    
                                                    <?php if(check_permission('invoice.pay')): ?>
                                                        <?php if($data->total_due > 0): ?>
                                                            <a class="dropdown-item"
                                                                href="<?php echo e(url('invoice/pay/' . $data->id)); ?>"
                                                                class="btn btn-success-rgba">
                                                                <i class="feather icon-dollar-sign"></i> Due
                                                            </a>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                    
                                                    <?php if($data->total_due < 0): ?>
                                                        <a href="#" data-toggle="modal"
                                                            data-target="#editModal-<?php echo e($data->id); ?>"
                                                            class="dropdown-item text-primary">
                                                            <i class="fa fa-undo"></i> Return amount
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    <?php if(check_permission('return.create')): ?>
                                                        <a href="<?php echo e(url('return/sale/'.$data->id)); ?>" class="dropdown-item"
                                                            class="btn btn-danger-rgba">
                                                            <i class="fa fa-undo"></i> Return
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    <?php if(check_permission('invoice.exchange')): ?>
                                                        <a href="<?php echo e(url('invoice/exchange/'.$data->id)); ?>" class="dropdown-item"
                                                            class="btn btn-danger-rgba">
                                                            <i class="fa fa-undo"></i> Exchange
                                                        </a>
                                                    <?php endif; ?>
                                                    
                                                    
                                                    
                                                        <a href="<?php echo e(route('inv.edit',$data->id)); ?>" class="dropdown-item"
                                                            class="btn btn-danger-rgba">
                                                            <i class="fa fa-pencil-square-o"></i> Edit
                                                        </a>
                                                    
                                                    
                                                    <a class="dropdown-item" href="<?php echo e(route('invoice.print', $data->id)); ?>"
                                                        class="btn btn-success-rgba">
                                                        <i class="feather icon-printer"></i> Print
                                                    </a>
                                                    <?php
                                                        $return_tbl = App\Models\ReturnTbl::where('invoice_id',$data->id)->first();
                                                        $del_invoice = App\Models\Invoice::where('id',$data->id)->latest()->first();
                                                        // dd($del_invoice->id);
                                                    ?>
                                                    
                                                    
                                                    <?php if(check_permission('invoice.destroy')): ?>
                                                        <?php if($return_tbl?->invoice_id != $data->id ): ?>
                                                        <a href="#" class="dropdown-item" data-toggle="modal"
                                                            data-target="#deleteModal-<?php echo e($data->id); ?>"
                                                            class="btn btn-danger-rgba">
                                                            <i class="feather icon-trash"></i> Delete 
                                                        </a>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>

                                    
                                    <form action="<?php echo e(route('invoice.return.amount',$data->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        
                                        <?php if (isset($component)) { $__componentOriginal8c9069a376d468665d9f4eee9640e8b7 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8c9069a376d468665d9f4eee9640e8b7 = $attributes; } ?>
<?php $component = App\View\Components\EditModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('edit-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\EditModal::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Payment Amount','sizeClass' => 'modal-md','id' => ''.e($data->id).'']); ?>
                                            <div class="mt-2 col-md-12">
                                                <label class="form-label font-weight-bold">Date</label>
                                                <input type="date" class="form-control" value="<?php echo e(date('Y-m-d')); ?>" name="date">
                                                <div class="error"><?php echo e(($errors->has('date'))?$errors->first('date'):''); ?></div>
                                            </div>
                                            <div class="mt-2 col-md-12">
                                                <label class="form-label font-weight-bold">Bank Account *</label>
                                                <?php
                                                    $bank_accounts = App\Models\BankAccount::where('status',1)->orderBy('bank_name','asc')->get();
                                                ?>
                                                <select class="select2" name="bank_id">
                                                    <?php $__currentLoopData = $bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($bank_account->id); ?>" >
                                                            <?php echo e($bank_account->bank_name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </div>
                                            
                                            <div class="mt-2 col-md-12">
                                                <input type="text" name="return_cus_amount" id="" value="<?php echo e($data->total_paid); ?>">
                                                <label for="return_paid_amount" class="form-label fw-bold">Amount *</label>
                                                <input type="number" class="form-control" min="1" step="any" required
                                                    placeholder="Enter Amount" name="return_paid_amount" value="<?php echo e(abs($data->total_paid)); ?>">
                                                <div class="error"><?php echo e(($errors->has('return_paid_amount'))?$errors->first('return_paid_amount'):''); ?></div>
                                            </div>
                                         <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8c9069a376d468665d9f4eee9640e8b7)): ?>
<?php $attributes = $__attributesOriginal8c9069a376d468665d9f4eee9640e8b7; ?>
<?php unset($__attributesOriginal8c9069a376d468665d9f4eee9640e8b7); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8c9069a376d468665d9f4eee9640e8b7)): ?>
<?php $component = $__componentOriginal8c9069a376d468665d9f4eee9640e8b7; ?>
<?php unset($__componentOriginal8c9069a376d468665d9f4eee9640e8b7); ?>
<?php endif; ?>
                                    </form>
                                    
                                    <form action="<?php echo e(route('invoice.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' => 'Invoice','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 Invoice Found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot>
                                <tr class="text-right header_bg">
                                    <td colspan="5" class="header_style_left text-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="4" class="header_style_right"></td>

                                </tr>
                            </tfoot>
                        </table>
                        <?php echo e($invoices->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 E:\laragon\www\organic\resources\views/backend/pages/invoice/index.blade.php ENDPATH**/ ?>