<?php

namespace App\Controllers\Owner;

use App\Controllers\BaseController;
use App\Models\ProfitTargetModel;

class ProfitTarget extends BaseController
{
    public function index()
    {
        $model = new ProfitTargetModel();
        $data['targets'] = $model->orderBy('tahun', 'DESC')->orderBy('bulan', 'DESC')->findAll();
        return view('owner/finance/target_profit', $data);
    }

    public function save()
    {
        $model = new ProfitTargetModel();
        $model->save([
            'bulan'          => $this->request->getPost('bulan'),
            'tahun'          => $this->request->getPost('tahun'),
            'target_nominal' => $this->request->getPost('target_nominal')
        ]);
        return redirect()->to('/owner/profittarget')->with('success', 'Target profit berhasil diatur.');
    }
}