

<?php $__env->startSection('title', 'Lease Reports'); ?>

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

<div class="card">

    <div class="card-header">

        <h4 class="mb-0">
            Lease Reports Dashboard
        </h4>

    </div>

    <div class="card-body">

        

        <form method="GET">

            <div class="row g-3 mb-4">

                <div class="col-md-2">

                    <label class="form-label">
                        Status
                    </label>

                    <select
                        name="status"
                        class="form-select">

                        <option value="">
                            All Status
                        </option>

                        <option value="active"
                            <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>
                            Active
                        </option>

                        <option value="audited"
                            <?php echo e(request('status') == 'audited' ? 'selected' : ''); ?>>
                            Audited
                        </option>

                        <option value="arrived_border"
                            <?php echo e(request('status') == 'arrived_border' ? 'selected' : ''); ?>>
                            Arrived Border
                        </option>

                        <option value="returned"
                            <?php echo e(request('status') == 'returned' ? 'selected' : ''); ?>>
                            Returned
                        </option>

                        <option value="completed"
                            <?php echo e(request('status') == 'completed' ? 'selected' : ''); ?>>
                            Completed
                        </option>

                        <option value="cancelled"
                            <?php echo e(request('status') == 'cancelled' ? 'selected' : ''); ?>>
                            Cancelled
                        </option>

                    </select>

                </div>

                <div class="col-md-3">

                    <label class="form-label">
                        Sales Officer
                    </label>

                    <select
                        name="sales_user_id"
                        class="form-select">

                        <option value="">
                            All Sales Officers
                        </option>

                        <?php $__currentLoopData = $salesUsers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                            <option
                                value="<?php echo e($user->id); ?>"
                                <?php echo e(request('sales_user_id') == $user->id ? 'selected' : ''); ?>>

                                <?php echo e($user->name); ?>


                            </option>

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

                    </select>

                </div>

                <div class="col-md-2">

                    <label class="form-label">
                        Cargo Type
                    </label>

                    <select
                        name="cargo_type"
                        class="form-select">

                        <option value="">
                            All Cargo
                        </option>

                        <option value="CONTAINERIZED"
                            <?php echo e(request('cargo_type') == 'CONTAINERIZED' ? 'selected' : ''); ?>>
                            CONTAINERIZED
                        </option>

                        <option value="IT"
                            <?php echo e(request('cargo_type') == 'IT' ? 'selected' : ''); ?>>
                            IT
                        </option>

                        <option value="DRY CARGO"
                            <?php echo e(request('cargo_type') == 'DRY CARGO' ? 'selected' : ''); ?>>
                            DRY CARGO
                        </option>

                        <option value="FUEL TANKER"
                            <?php echo e(request('cargo_type') == 'FUEL TANKER' ? 'selected' : ''); ?>>
                            FUEL TANKER
                        </option>

                        <option value="BOX BODY"
                            <?php echo e(request('cargo_type') == 'BOX BODY' ? 'selected' : ''); ?>>
                            BOX BODY
                        </option>

                    </select>

                </div>

                <div class="col-md-2">

                    <label class="form-label">
                        Start Date & Time
                    </label>

                    <input
                        type="datetime-local"
                        name="start_date"
                        value="<?php echo e(request('start_date')); ?>"
                        class="form-control">

                </div>

                <div class="col-md-2">

                    <label class="form-label">
                        End Date & Time
                    </label>

                    <input
                        type="datetime-local"
                        name="end_date"
                        value="<?php echo e(request('end_date')); ?>"
                        class="form-control">

                </div>

                <div class="col-md-1 d-grid">

                    <label class="form-label">
                        &nbsp;
                    </label>

                    <button
                        class="btn btn-primary">

                        Filter

                    </button>

                </div>

            </div>

        </form>

        

        <div class="row mb-4">

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

                <div class="card border-primary">

                    <div class="card-body text-center">

                        <h6 class="text-muted">
                            Total Leases
                        </h6>

                        <h2 class="text-primary">

                            <?php echo e(number_format($totalLeases)); ?>


                        </h2>

                    </div>

                </div>

            </div>

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

                <div class="card border-success">

                    <div class="card-body text-center">

                        <h6 class="text-muted">
                            Grand Total Amount
                        </h6>

                        <h2 class="text-success">

                            TZS <?php echo e(number_format($grandTotal,2)); ?>


                        </h2>

                    </div>

                </div>

            </div>

        </div>

        

        <div class="row mb-4">

            <div class="col-lg-8">

                <div class="card">

                    <div class="card-header">

                        <strong>
                            Sales Summary By Cargo Type
                        </strong>

                    </div>

                    <div class="card-body p-0">

                        <table class="table table-bordered mb-0">

                            <thead class="table-light">

                                <tr>

                                    <th>
                                        Cargo Type
                                    </th>

                                    <th class="text-center">
                                        Qty
                                    </th>

                                    <th class="text-end">
                                        Amount
                                    </th>

                                </tr>

                            </thead>

                            <tbody>

                                <?php $__empty_1 = true; $__currentLoopData = $cargoSummary; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>

                                    <tr>

                                        <td>

                                            <strong>

                                                <?php echo e($row->cargo_type); ?>


                                            </strong>

                                        </td>

                                        <td class="text-center">

                                            <?php echo e(number_format($row->qty)); ?>


                                        </td>

                                        <td class="text-end">

                                            <?php echo e(number_format($row->amount,2)); ?>


                                        </td>

                                    </tr>

                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>

                                    <tr>

                                        <td
                                            colspan="3"
                                            class="text-center">

                                            No Data

                                        </td>

                                    </tr>

                                <?php endif; ?>

                            </tbody>

                            <tfoot>

                                <tr class="table-secondary">

                                    <th>

                                        GRAND TOTAL

                                    </th>

                                    <th class="text-center">

                                        <?php echo e(number_format($totalLeases)); ?>


                                    </th>

                                    <th class="text-end">

                                        <?php echo e(number_format($grandTotal,2)); ?>


                                    </th>

                                </tr>

                            </tfoot>

                        </table>

                    </div>

                </div>

            </div>

            <div class="col-lg-4">

                <div class="card">

                    <div class="card-header">

                        <strong>

                            Summary By Status

                        </strong>

                    </div>

                    <div class="card-body p-0">

                        <table class="table table-bordered mb-0">

                            <tbody>

                                <?php $__currentLoopData = $statusSummary; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status => $qty): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                    <tr>

                                        <td>

                                            <?php echo e(strtoupper(str_replace('_',' ',$status))); ?>


                                        </td>

                                        <td class="text-end">

                                            <strong>

                                                <?php echo e(number_format($qty)); ?>


                                            </strong>

                                        </td>

                                    </tr>

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

                            </tbody>

                        </table>

                    </div>

                </div>

            </div>

        </div>

        

        <div class="table-responsive">

            <table
    class="table table-striped table-bordered align-middle"
    id="leaseReportTable">

    <thead class="table-light">

        <tr>

            <th>#</th>

            <th>Lease No</th>

            <th>Device</th>

            <th>Sub T1</th>

            <th>Truck No</th>

            <th>Trailer</th>

            <th>Driver</th>

            <th>Cargo</th>

            <th>Border</th>

            <th>Tag Point</th>

            <th>Sales Officer</th>

            <th class="text-end">
                Amount
            </th>

            <th>Status</th>

            <th>Lease Date</th>

        </tr>

    </thead>

    <tbody>

        <?php $__empty_1 = true; $__currentLoopData = $leases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lease): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>

            <?php

                $colors = [

                    'active' => 'primary',

                    'audited' => 'info',

                    'arrived_border' => 'warning',

                    'returned' => 'secondary',

                    'completed' => 'success',

                    'cancelled' => 'danger',

                ];

            ?>

            <tr>

                <td>

                    <?php echo e($loop->iteration); ?>


                </td>

                <td>

                    <strong>

                        <?php echo e($lease->lease_no); ?>


                    </strong>

                </td>

                <td>

                    <?php echo e($lease->device?->serial_number); ?>


                </td>

                <td>

                    <?php echo e($lease->sub_t1_no ?: '-'); ?>


                </td>

                <td>

                    <?php echo e($lease->truck_no); ?>


                </td>

                <td>

                    <?php echo e($lease->trailer_no ?: '-'); ?>


                </td>

                <td>

                    <strong>

                        <?php echo e($lease->driver_name); ?>


                    </strong>

                    <br>

                    <small class="text-muted">

                        <?php echo e($lease->driver_phone); ?>


                    </small>

                </td>

                <td>

                    <span class="badge bg-dark">

                        <?php echo e($lease->cargo_type); ?>


                    </span>

                </td>

                <td>

                    <?php echo e($lease->destination?->name); ?>


                </td>

                <td>

                    <?php echo e($lease->tagPoint?->name); ?>


                </td>

                <td>

                    <?php echo e($lease->salesUser?->name); ?>


                </td>

                <td class="text-end">

                    <strong>

                        <?php echo e(number_format($lease->amount,2)); ?>


                    </strong>

                </td>

                <td>

                    <span class="badge bg-<?php echo e($colors[$lease->status] ?? 'dark'); ?>">

                        <?php echo e(strtoupper(str_replace('_',' ',$lease->status))); ?>


                    </span>

                </td>

                <td>

                    <?php echo e($lease->leased_at?->format('d M Y H:i:s')); ?>


                </td>

            </tr>

        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>

            <tr>

                <td
                    colspan="14"
                    class="text-center text-muted">

                    No lease records found.

                </td>

            </tr>

        <?php endif; ?>

    </tbody>

</table>

</div>

</div>

</div>

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

<?php $__env->startPush('scripts'); ?>

<script>

$(function () {

    $('#leaseReportTable').DataTable({

        order: [

            [13,'desc']

        ],

        pageLength: 25,

        responsive: true,

        scrollX: true,

        dom: 'Bfrtip',

        buttons: [

            {

                extend: 'copy',

                className: 'btn btn-secondary'

            },

            {

                extend: 'excel',

                className: 'btn btn-success'

            },

            {

                extend: 'csv',

                className: 'btn btn-info'

            },

            {

                extend: 'print',

                className: 'btn btn-primary'

            }

        ]

    });

});

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\Projects\lms-ects\resources\views/reports/leases.blade.php ENDPATH**/ ?>