<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\SettingModel;
use App\Models\UserModel;
class Report extends BaseController
{
    public function all_donation_report()
    {
        if(isset($_GET['start_date']))
        {
            $start_date = $_GET['start_date'];
            $end_date = $_GET['end_date'];
        }
        else
        {
            $start_date = '';
            $end_date = date('Y-m-d');
        }
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_report'] = $setting->all_donation_report();
        
        echo view('admin/include/header', $data);
        echo view('admin/report/all_donation_report');
        echo view('admin/include/footer');
    }

    function all_volunteer_report()
    {
        $setting = new SettingModel();
        $user = new UserModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_users'] = $user->all_volunteer_report();
        echo view('admin/include/header', $data);
        echo view('admin/report/all_volunteer_report');
        echo view('admin/include/footer');
    }

    function all_subscribers_report()
    {
        $setting = new SettingModel();
        $user = new UserModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_users'] = $user->all_subscribers_report();
        echo view('admin/include/header', $data);
        echo view('admin/report/all_subscribers_report');
        echo view('admin/include/footer');
    }

    public function approve_donation($id)
    {
        $setting = new SettingModel();
        $data['donation_status'] = 1;
        if($setting->approve_donation($data, $id))
        {
            session()->set('success', "Donation Successfully Approved");
            return redirect()->back();
        }
        else
        {
            session()->set('error', "Donation Approved Failed");
            return redirect()->back();
        }
    }

    public function delete_donation($id)
    {
        $setting = new SettingModel();
        if($setting->delete_donation($id))
        {
            session()->set('success', "Donation Successfully Deleted");
            return redirect()->back();
        }
        else
        {
            session()->set('error', "Donation Deleted Failed");
            return redirect()->back();
        }
    }

   
    
}
