<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Income Statement Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            margin: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
        }
        .header h2 {
            margin: 0;
            font-size: 18px;
        }
        .info {
            margin-bottom: 20px;
        }
        .info p {
            margin: 5px 0;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 16px;
        }
        th, td {
            border: 1px solid #000;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
            font-weight: bold;
        }
        .text-right {
            text-align: right;
        }
        .section-title {
            margin-top: 20px;
            font-size: 14px;
            font-weight: bold;
        }
        .total-row {
            font-weight: bold;
            background-color: #e9ecef;
        }
        .net-income-row {
            font-weight: bold;
            background-color: #dbeafe;
        }
    </style>
</head>
<body>
    @include('modules.reports.partials.pdf-company-details')
    <div class="header">
        <h2>Income Statement Report</h2>
    </div>

    <div class="info">
        <p><strong>Date:</strong> {{ date('F j, Y') }}</p>
        <p><strong>Period:</strong> {{ $pfrom }} to {{ $pto }}</p>
        <p><strong>Currency:</strong> {{ $currencyName }}</p>
    </div>

    <div class="section-title">Revenues</div>
    <table>
        <thead>
            <tr>
                <th>Description</th>
                <th class="text-right">Amount</th>
            </tr>
        </thead>
        <tbody>
            @forelse($revenues as $revenue)
                <tr>
                    <td>{{ $revenue['description'] }}</td>
                    <td class="text-right">{{ number_format($revenue['amount'], 2) }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="2" style="text-align: center;">No revenue data found</td>
                </tr>
            @endforelse
        </tbody>
        <tfoot>
            <tr class="total-row">
                <td class="text-right"><strong>Total Revenues</strong></td>
                <td class="text-right"><strong>{{ number_format(collect($revenues)->sum('amount'), 2) }}</strong></td>
            </tr>
        </tfoot>
    </table>

    <div class="section-title">Expenses</div>
    <table>
        <thead>
            <tr>
                <th>Description</th>
                <th class="text-right">Amount</th>
            </tr>
        </thead>
        <tbody>
            @forelse($expenses as $expense)
                <tr>
                    <td>{{ $expense['description'] }}</td>
                    <td class="text-right">{{ number_format($expense['amount'], 2) }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="2" style="text-align: center;">No expense data found</td>
                </tr>
            @endforelse
        </tbody>
        <tfoot>
            <tr class="total-row">
                <td class="text-right"><strong>Total Expenses</strong></td>
                <td class="text-right"><strong>{{ number_format(collect($expenses)->sum('amount'), 2) }}</strong></td>
            </tr>
        </tfoot>
    </table>

    <table>
        <tbody>
            <tr class="net-income-row">
                <td class="text-right"><strong>Net Income</strong></td>
                <td class="text-right"><strong>{{ number_format($netIncome, 2) }}</strong></td>
            </tr>
        </tbody>
    </table>
</body>
</html>

