<?php $__env->startSection('title', 'Rent Summary Report'); ?>

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

<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800">Rent Summary Report</h1>
</div>
<?php if(session('success')): ?>
                            <div class="alert alert-success" id="successMessage"  style="margin: 20px;">
                                <?php echo e(session('success')); ?>

                            </div>
                    <?php endif; ?>

<div class="card shadow mb-4">
<?php if($errors->any()): ?>

<div class="form-group"  id="successMessage"  style="margin: 20px;">
    <div class="card bg-warning text-white shadow">
        <div class="card-body">

            <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div style="color: red; "><?php echo e($error); ?></div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        </div>
    </div>
</div>
<?php endif; ?>
        <form action="<?php echo e(route('RentSummaryReport')); ?>" method="GET">
            <?php echo csrf_field(); ?>

            <div class="form-group row">
                <div class="col-md-4 mb-3">
                    <label class="font-weight-bold text-secondary">Report Type</label>
                    <select class="form-control" name="report_type" id="reportType" required>
                        <option value="summary" <?php echo e(old('report_type') == 'summary' ? 'selected' : ''); ?>>Summary</option>
                        <option value="detailed" <?php echo e(old('report_type') == 'detailed' ? 'selected' : ''); ?>>Detailed</option>
                    </select>
                </div>
                <div class="col-md-4 mb-3">
    <label class="font-weight-bold text-secondary">Date From</label>
    <input type="date" class="form-control" name="from_date" value="<?php echo e(old('from_date', request()->get('from_date', now()->format('Y-m-d')))); ?>" required>
</div>

<div class="col-md-4 mb-3">
    <label class="font-weight-bold text-secondary">Date To</label>
    <input type="date" class="form-control" name="to_date" value="<?php echo e(old('to_date', request()->get('to_date', now()->format('Y-m-d')))); ?>" required>
</div>

            </div>

            <div style="display: flex;">
                <button type="submit" id="viewButton" style="width: 100px; height: 40px; margin-right: 10px; margin-top: 6px" class="btn btn-primary btn-user btn-block">View</button>
                <button type="button" id="refreshButton" style="width: 100px;" class="btn btn-secondary btn-user btn-block">Refresh</button>
            </div>
        </form>
    </div>

            <!-- Report Tables -->
            <div class="card-body">
            <?php if($summaryData->isNotEmpty()): ?>
            <div id="summaryTable">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Tenant Code</th>
                            <th>Name</th>
                            <th>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $summaryData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e(\Carbon\Carbon::parse($data->entrydate)->format('F j, Y')); ?></td>
                                <td><?php echo e($data->tenantcode); ?></td>
                                <td><?php echo e($data->tenant_name); ?></td>
                                <td>USD<?php echo e(number_format($data->total, 2)); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                <tr>
                    <td colspan="3" class="font-weight-bold text-right">Grand Total</td>
                    <td class="font-weight-bold">USD<?php echo e(number_format($grandTotal, 2)); ?></td>
                </tr>
            </tfoot>
                </table>
            </div>
        <?php else: ?>
            <div id="summaryTable">
                <p>No summary data available.</p>
            </div>
        <?php endif; ?>


        <?php if($detailedData->isNotEmpty()): ?>
    <div id="detailedTable">
        <?php $__currentLoopData = $detailedData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tenantName => $transactions): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="tenant-section" style="margin-top: 30px; page-break-inside: avoid;">
                <h4 style="margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 8px;">
                    <strong>Tenant:</strong> <?php echo e($tenantName); ?>

                </h4>
                <table class="table table-striped table-bordered" style="width: 100%; margin-bottom: 15px;">
                    <thead>
                        <tr>
                            <th style="width: 15%;">Date</th>
                            <th style="width: 15%;">Invoice #</th>  
                            <th style="width: 30%;">Contact person</th>
                            <th style="width: 20%;" class="text-right">Amount(USD)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $tenantTotal = 0;
                        ?>
                        <?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $txn): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $amount = $txn->total ?? 0;
                                $tenantTotal += $amount;
                            ?>
                            <tr>
                                <td><?php echo e(\Carbon\Carbon::parse($txn->entrydate)->format('d/m/Y')); ?></td>
                                <td><?php echo e($txn->batch); ?></td>
                                <td><?php echo e($txn->contactperson); ?></td>
                                <td class="text-right"><?php echo e(number_format($amount, 2)); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
<?php else: ?>
    <div id="detailedTable">
        <p>No detailed data available.</p>
    </div>
<?php endif; ?>





</div>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        let reportType = document.getElementById("reportType");
        let summaryTable = document.getElementById("summaryTable");
        let detailedTable = document.getElementById("detailedTable");

        function showCorrectTable() {
            summaryTable.style.display = "none";
            detailedTable.style.display = "none";

            if (reportType.value === "summary") {
                summaryTable.style.display = "block";
            } else if (reportType.value === "detailed") {
                detailedTable.style.display = "block";
            }
        }

        showCorrectTable(); // Run on page load
        reportType.addEventListener("change", showCorrectTable); // Change event
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.nav', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\pinetops\re.pro\resources\views//Rentsummary.blade.php ENDPATH**/ ?>