<?php

namespace App\Http\Controllers;

use App\Models\Currency;
use App\Models\Expense;
use Illuminate\Http\Request;

class ExpenseController extends Controller
{
    public function index() { return view('expenses.index', ['expenses' => Expense::latest('expense_date')->paginate(15), 'currencies' => Currency::where('is_active', true)->get()]); }
    public function store(Request $request) { Expense::create($request->validate(['category' => ['required', 'string', 'max:80'], 'amount' => ['required', 'numeric', 'gt:0'], 'currency_code' => ['required', 'exists:currencies,code'], 'method' => ['required', 'in:cash,bank,mobile,other'], 'expense_date' => ['required', 'date'], 'reference' => ['nullable', 'string', 'max:100'], 'notes' => ['nullable', 'string']])); return back()->with('success', __('Expense recorded.')); }
    public function destroy(Expense $expense) { $expense->delete(); return back()->with('success', __('Expense removed.')); }
}
