<?php $__env->startSection('title', 'Income Statements'); ?>
<?php $__env->startSection('content'); ?>

<div class="container-fluid py-3">
        <div class="d-flex justify-content-end mb-3">
            <a href="<?php echo e(route('modules.reports')); ?>" class="btn-back">
                <i class="fas fa-arrow-left me-2"></i> Back to Reports
            </a>
        </div>

    <div class="card shadow-sm">
        <div class="card-header bg-primary text-white py-3">
            <h5 class="mb-0"><i class="fas fa-chart-line me-2"></i> Income Statements</h5>
        </div>

        <div class="card-body">
            <?php if(session('success')): ?>
                <div class="alert alert-success"><?php echo e(session('success')); ?></div>
            <?php endif; ?>

            <?php if($errors->any()): ?>
                <div class="alert alert-danger">
                    <ul class="mb-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>
                </div>
            <?php endif; ?>

            <form action="<?php echo e(route('incomeStatements.generate')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="row mb-3">
                    <div class="col-md-4">
                        <label class="form-label"><strong>From Period</strong></label>
                        <input type="date" class="form-control" name="pfrom" value="<?php echo e(old('pfrom', date('Y-m-d'))); ?>" required>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label"><strong>To Period</strong></label>
                        <input type="date" class="form-control" name="pto" value="<?php echo e(old('pto', date('Y-m-d'))); ?>" required>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label"><strong>Select Currency</strong></label>
                        <select class="form-control" name="curr" required>
                            <option value="" disabled <?php echo e(old('curr', $currencyId ?? '') ? '' : 'selected'); ?>>Select Currency</option>
                            <?php $__currentLoopData = $currencies ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($currency->currency_id); ?>" <?php echo e(old('curr', $currencyId ?? '') == $currency->currency_id ? 'selected' : ''); ?>>
                                    <?php echo e($currency->currency_name); ?>

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

                <div class="d-flex justify-content-end">
                    <button type="submit" class="btn btn-primary me-2">Generate Report</button>
                    <button type="reset" class="btn btn-secondary">Refresh</button>
                </div>
            </form>

            <hr>

            <?php if(isset($revenues) && isset($expenses)): ?>
                <div class="d-flex justify-content-end mb-3 gap-2 no-print">
                    <button type="button" class="btn btn-primary" onclick="window.print()">
                        <i class="fas fa-print me-2"></i> Print Report
                    </button>
                    <form action="<?php echo e(route('incomeStatements.downloadPdf')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="pfrom" value="<?php echo e($pfrom ?? ''); ?>">
                        <input type="hidden" name="pto" value="<?php echo e($pto ?? ''); ?>">
                        <input type="hidden" name="currencyId" value="<?php echo e($currencyId ?? ''); ?>">
                        <button type="submit" class="btn btn-success">
                            <i class="fas fa-download me-2"></i> Download PDF
                        </button>
                    </form>
                </div>

                <div class="report-container">
                    <div class="report-header mb-4">
                        <div class="d-flex align-items-center mb-3">
                            <img src="<?php echo e(asset('img/logo.png')); ?>" alt="Logo" style="height: 60px;" class="me-3">
                            <h4 class="mb-0">Income Statement</h4>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <p class="mb-1"><strong>Date:</strong> <?php echo e(date('F j, Y')); ?></p>
                                <p class="mb-1"><strong>Period:</strong> <?php echo e($pfrom ?? 'N/A'); ?> to <?php echo e($pto ?? 'N/A'); ?></p>
                            </div>
                            <div class="col-md-6 text-md-end">
                                <p class="mb-1"><strong>Currency:</strong> <?php echo e($currnames[$currencyId] ?? 'USD'); ?></p>
                            </div>
                        </div>
                    </div>

                    <!-- Revenues Section -->
                    <h5 class="bg-light p-2 border-bottom">Revenues</h5>
                    <div class="table-responsive mb-4">
                        <table class="table table-bordered">
                            <thead class="table-light">
                                <tr>
                                    <th>Description</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $revenues; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $revenue): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($revenue['description']); ?></td>
                                        <td class="text-end"><?php echo e(number_format($revenue['amount'], 2)); ?></td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="2" class="text-center">No revenue data found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot class="table-secondary">
                                <tr>
                                    <td class="text-end"><strong>Total Revenues</strong></td>
                                    <td class="text-end"><strong><?php echo e(number_format(collect($revenues ?? [])->sum('amount'), 2)); ?></strong></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <!-- Expenses Section -->
                    <h5 class="bg-light p-2 border-bottom">Expenses</h5>
                    <div class="table-responsive mb-4">
                        <table class="table table-bordered">
                            <thead class="table-light">
                                <tr>
                                    <th>Description</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $expense): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($expense['description']); ?></td>
                                        <td class="text-end"><?php echo e(number_format($expense['amount'], 2)); ?></td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="2" class="text-center">No expense data found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                            <tfoot class="table-secondary">
                                <tr>
                                    <td class="text-end"><strong>Total Expenses</strong></td>
                                    <td class="text-end"><strong><?php echo e(number_format(collect($expenses ?? [])->sum('amount'), 2)); ?></strong></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <!-- Net Income Section -->
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <tbody>
                                <tr class="table-primary">
                                    <td class="text-end"><strong>Net Income</strong></td>
                                    <td class="text-end"><strong><?php echo e(number_format((collect($revenues ?? [])->sum('amount')) - (collect($expenses ?? [])->sum('amount')), 2)); ?></strong></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

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

<?php $__env->startSection('styles'); ?>
<style>
.btn-back {
    text-decoration: none;
    color: #1AB9D9;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    padding: 5px 15px;
    border-radius: 4px;
    transition: all 0.3s;
}
.btn-back:hover {
    background-color: rgba(26, 185, 217, 0.1);
    text-decoration: none;
}
.card {
    border-radius: 8px;
    overflow: hidden;
    border: none;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}
.card-header {
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding: 12px 20px;
}
.table th {
    background-color: #f8f9fa;
}
.report-header {
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 20px;
}

@media print {
    .no-print,
    .btn-back,
    form,
    .card-header {
        display: none !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
</style>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\admin\Desktop\prolex\resources\views/modules/reports/income-statements.blade.php ENDPATH**/ ?>