<?php
namespace App\Controllers;

use App\Core\Controller;
use App\Models\DailyFloat;

class DailyFloatController extends Controller
{
    public function index()
    {
        $this->requireAuth();
        $floatModel = new DailyFloat();
        $latest = $floatModel->getLatest();
        $this->render('daily_float/index', ['latest' => $latest]);
    }

    public function createForm()
    {
        $this->requireAuth();
        $this->render('daily_float/create');
    }

    public function store()
    {
        $this->requireAuth();
        $model = new DailyFloat();
        $data = [
            'record_date' => $_POST['record_date'],
            'cash_kes' => $_POST['cash_kes'],
            'cash_usd' => $_POST['cash_usd'],
            'cash_eur' => $_POST['cash_eur'],
            'cash_gbp' => $_POST['cash_gbp'],
            'mpesa_float' => $_POST['mpesa_float'],
            'bank_kes' => $_POST['bank_kes'],
            'bank_usd' => $_POST['bank_usd'],
            'rate_usd' => $_POST['rate_usd'],
            'rate_eur' => $_POST['rate_eur'],
            'rate_gbp' => $_POST['rate_gbp'],
            'notes' => $_POST['notes'],
            'recorded_by' => $_SESSION['user_id']
        ];
        $model->create($data);
        $this->redirect('/daily-float');
    }
}