<?php

namespace App\Controllers;

use App\Models\FolioLineItemModel;
use App\Models\FolioPaymentModel;

/**
 * Manager-only landing page tying together the billing/finance-related
 * screens that already exist as separate pages (Rate Plans, Corporate
 * Accounts, Integration Settings) — added for the sidebar redesign
 * (see the "Billing & Finance" nav item) rather than building a new
 * standalone finance module from scratch. Also surfaces this month's
 * revenue at a glance, reusing the same category breakdown the dashboard
 * uses (see FolioLineItemModel::byCategoryOn/totalOn).
 */
class BillingFinanceController extends BaseController
{
    public function index()
    {
        $lineItems = new FolioLineItemModel();
        $payments  = new FolioPaymentModel();

        $monthStart = date('Y-m-01');
        $monthEnd   = date('Y-m-t');

        return view('billing_finance/index', [
            'pageTitle'       => 'Billing & Finance',
            'monthRevenue'    => $lineItems->totalBetween($monthStart, $monthEnd),
            'monthByCategory' => $lineItems->byCategoryBetween($monthStart, $monthEnd),
            'monthCollected'  => $payments->totalBetween($monthStart, $monthEnd),
        ]);
    }
}
