
<?php $__env->startSection('style'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="container">

        <div class="alert-section">
            <?php if($errors->any()): ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">

                    <ul class="list-unstyled m-0 p-0">
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li>
                                <?php echo e($error); ?>

                            </li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    </ul>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                </div>
            <?php endif; ?>



            
            <?php if(session('error')): ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <?php echo e(session('error')); ?>

                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                </div>
            <?php endif; ?>

            


            <?php if(session('success')): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <ul class="list-unstyled m-0 p-0">
                        <?php echo e(session('success')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                    </ul>
                </div>
            <?php endif; ?>



            <?php if(session('warning')): ?>
                <div class="alert alert-warning alert-dismissible fade show" role="alert">
                    <ul class="list-unstyled m-0 p-0">
                        <?php echo e(session('warning')); ?>

                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                    </ul>
                </div>
            <?php endif; ?>


        </div>


        <div class="card">
            <div class="card-header"><strong>View Invoice</strong></div>



            <div class="card-body">
                <div class="row">
                    <div> <a class="btn btn btn-outline-info  mb-3" href="<?php echo e(url()->previous()); ?>"><i
                                class="bi bi-skip-backward-circle pr-1"></i> Back</a>
                    </div>
                    <div class="col-md-6">



                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Name : </label>
                            <div class="col-sm-8">
                                <input type="text" name="name" class="form-control"
                                    value="<?php echo e($invoice->customer_name); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">NIC : </label>
                            <div class="col-sm-8">
                                <input type="text" name="nic" class="form-control"
                                    value="<?php echo e($invoice->customer_nic); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Mobile : </label>
                            <div class="col-sm-8">
                                <input type="text" name="mobile" class="form-control"
                                    value="<?php echo e($invoice->customer_mobile); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Land : </label>
                            <div class="col-sm-8">
                                <input type="text" name="land" class="form-control"
                                    value="<?php echo e($invoice->customer_land); ?>" disabled>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Address : </label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="address" id="" cols="30" rows="4" disabled><?php echo e($invoice->customer_address); ?></textarea>
                            </div>
                        </div>




                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Picture : </label>
                            <div class="col-sm-8">
                                <img class="img img-thumbnail" id="picture_preview"
                                    src="<?php echo e(!($invoice->picture_name == '' || $invoice->picture_name == null) ? asset('storage/' . $invoice->picture_name) : asset('storage/images/default/sample-image-document.jpg')); ?>"
                                    alt="" width="250" height="250">
                            </div>


                        </div>














                    </div>
                    <div class="col-md-6">

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Date : </label>
                            <div class="col-sm-8">
                                <input type="date" name="date" class="form-control" value="<?php echo e($invoice->date); ?>"
                                    disabled>

                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Salesman : </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?php echo e($invoice->salesman->name); ?>"
                                    disabled>
                                
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Item : </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?php echo e($invoice->item->name); ?>" disabled>

                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Bill Type : </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?php echo e($invoice->type); ?>" disabled>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Item Amount : </label>
                            <div class="col-sm-8">
                                <input type="double" name="amount" class="form-control"
                                    value="<?php echo e(number_format($invoice->amount, 2)); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Discount : </label>
                            <div class="col-sm-8">
                                <input type="double" name="discount" class="form-control"
                                    value="<?php echo e(number_format($invoice->discount, 2)); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Bill Amount : </label>
                            <div class="col-sm-8">
                                <input type="double" name="bill-amount" class="form-control"
                                    value="<?php echo e(number_format($invoice->amount - $invoice->discount, 2)); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Paid Amount : </label>
                            <div class="col-sm-8">
                                <input type="double" name="paid-amount" class="form-control"
                                    value="<?php echo e(number_format($invoice->payment_sum_amount, 2)); ?>" disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Not Paid Amount : </label>
                            <div class="col-sm-8">
                                <input type="double" name="notpaid-amount" class="form-control"
                                    value="<?php echo e(number_format($invoice->amount - $invoice->discount - $invoice->payment_sum_amount, 2)); ?>"
                                    disabled>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Status : </label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<?php echo e($invoice->status); ?>" disabled>

                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="name" class="col-sm-4 col-form-label">Note : </label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="note" id="" cols="30" rows="4" disabled><?php echo e($invoice->note); ?></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        

        <div class="invoice_payment_data mt-3">
            <div class="card">
                <div class="card-header">
                    <strong>Payment Data</strong>
                </div>
                <div class="card-body">

                    <?php
                        $total_payment = 0;
                        $total_amount = 0;
                    ?>

                    <table class="table table-hover table-responsive-lg fs-6">
                        <thead class="thead-light">
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">Code</th>
                                <th scope="col">Date</th>
                                <th scope="col">Type</th>
                                <th scope="col">Amount</th>
                                



                            </tr>
                        </thead>
                        <tbody>
                            <?php $__currentLoopData = $invoice->payment; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($loop->iteration); ?></td>
                                    <td><?php echo e($payment->code); ?></td>
                                    <td><?php echo e($payment->date); ?></td>
                                    <td><?php echo e($payment->type); ?></td>
                                    <td><?php echo e(number_format($payment->amount, 2)); ?></td>

                         
                                    <?php
                                        $total_payment++;
                                        $total_amount += $payment->amount;
                                    ?>


                                    </td>

                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                        </tbody>
                    </table>


                    <div class="total_data">
                        <div class="row g-3 d-flex justify-content-end">
                            <div class="col-auto">
                                <label for="inputPassword6" class="col-form-label col-form-label-sm">Total
                                    Payment</label>
                            </div>
                            <div class="col-auto">
                                <input type="text" name="total_payment"
                                    class="form-control form-control-sm text-end fw-bold" readonly
                                    value="<?php echo e($total_payment); ?>" style="width: 120px;">
                            </div>

                        </div>


                        <div class="row g-3 d-flex justify-content-end pt-1">
                            <div class="col-auto">
                                <label for="inputPassword6" class="col-form-label col-form-label-sm">Total
                                    Amount</label>
                            </div>
                            <div class="col-auto">
                                <input type="text" name="total_amount"
                                    class="form-control form-control-sm text-end fw-bold" readonly
                                    value="<?php echo e(number_format($total_amount, 2)); ?>" style="width: 120px;">
                            </div>

                        </div>
                    </div>

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


        
        <div class="row mt-3">
            <div class="col-md-6 mb-3">
                <div class="card">
                    <div class="card-header text-danger"><strong>Return Invoice</strong></div>
                    <div class="card-body">

                        

                            <div class="form-group row">
                                <label for="name" class="col-sm-4 col-form-label">Is return invoice : </label>
                                <div class="col-sm-8">
                                    <input type="text" name="is-return" class="form-control"
                                        value="<?php echo e($invoice->return ? 'Yes' : 'No'); ?>" disabled>

                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="name" class="col-sm-4 col-form-label">Date : </label>
                                <div class="col-sm-8">
                                    <input type="date" name="date" class="form-control" value="<?php echo e($invoice->return ? $invoice->return->date : ''); ?>">

                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="name" class="col-sm-4 col-form-label">Return Amount : </label>
                                <div class="col-sm-8">
                                    <input type="textx" name="amount" class="form-control" value="<?php echo e($invoice->return ? number_format($invoice->return->amount,2) : ''); ?>">

                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="name" class="col-sm-4 col-form-label">Note : </label>
                                <div class="col-sm-8">
                                    <textarea class="form-control" id="" cols="30" rows="5" name="note"><?php echo e($invoice->return ? $invoice->return->note :''); ?></textarea>

                                </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-sm-4"></div>
                                <div class="col-sm-8">
                                    <div class="d-flex align-items-center gap-2">

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

        </div>
    </div>

    </div>


    

    <div class="col-md-6 mb-3">
        <div class="card">
            <div class="card-header text-warning"><strong>Cancel Invoice</strong></div>
            <div class="card-body">


            

                    <div class="form-group row">
                        <label for="name" class="col-sm-4 col-form-label">Is cancel invoice : </label>
                        <div class="col-sm-8">
                            <input type="text" name="is-cancel-invoice" class="form-control"
                                value="<?php echo e($invoice->cancel ? 'Yes' : 'No'); ?>" disabled>

                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="name" class="col-sm-4 col-form-label">Date : </label>
                        <div class="col-sm-8">
                            <input type="date" name="date" class="form-control" value="<?php echo e($invoice->cancel ? $invoice->cancel->date : ''); ?>">

                        </div>
                    </div>

                    <div class="form-group row">
                        <label for="name" class="col-sm-4 col-form-label">Note : </label>
                        <div class="col-sm-8">
                            <textarea class="form-control" cols="30" rows="5" name="note"><?php echo e($invoice->cancel != null ? $invoice->cancel->note : ''); ?></textarea>

                        </div>
                    </div>

                    <div class="form-group row">
                        <div class="col-sm-4"></div>
                        <div class="col-sm-8">
                            <div class="d-flex align-items-center gap-2">

            </div>


        </div>
    </div>


    </div>



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



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

<?php $__env->startSection('script'); ?>
    <script>
        // document 6 before upload
        // document.getElementById('picture').addEventListener('change', function(event) {
        //     const file = event.target.files[0];
        //     if (file) {
        //         const preview = document.getElementById('picture_preview');
        //         preview.src = URL.createObjectURL(file);
        //         preview.style.display = "block";
        //     }
        // });





        //invoice edit validation
        $('#btn-edit').click(function(e) {
            e.preventDefault();
            var form = $(this).closest('form');
            //alert('aaa');
            Swal.fire({
                title: "Are you sure edit invoice data ?",
                text: "Please concern clearly before edit",
                icon: "warning",
                showCancelButton: true,
                confirmButtonColor: "#3085d6",
                cancelButtonColor: "#d33",
                confirmButtonText: "Yes, update it !"
            }).then((result) => {
                if (result.isConfirmed) {
                    // Swal.fire({
                    //   title: "Deleted!",
                    //   text: "Your file has been deleted.",
                    //   icon: "success"
                    // });
                    form.submit();
                }
            });

        });


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

<?php echo $__env->make('template.layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\HirePurchasingManagementSolution\resources\views/invoice/view.blade.php ENDPATH**/ ?>