<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Payout extends Admin_Core_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model', 'user');
    }

    public function view_all_advane_salary()
    {
        if(isset($_POST['search'])) 
        {
            $data['cur_date'] = date('M', strtotime($this->input->post('date'))).', '.date('Y', strtotime($this->input->post('date')));
            $month = date('m', strtotime($this->input->post('date')));
            $year = date('Y', strtotime($this->input->post('date'))); 
            $data['app_setting'] = $this->setting_model->get_all_app_setting();
            $data['all_salary_adv'] = $this->user->get_all_salary_advance($month, $year);
            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/emp_payout/view_all_advance_salary');
            $this->load->view('admin/include/footer');
        }
        else
        {
            $data['cur_date'] = date('M, Y');
            $month = date('m');
            $year = date('Y'); 
            $data['app_setting'] = $this->setting_model->get_all_app_setting();
            $data['all_salary_adv'] = $this->user->get_all_salary_advance($month, $year);
            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/emp_payout/view_all_advance_salary');
            $this->load->view('admin/include/footer');
        }
    }

    function add_advance_salary_details()
    {
        if ($this->user->add_advance_salary_details()) 
        {
            $this->session->set_userdata('success', "Salary Successfully Added");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Salary Added Failed");
            redirect($this->agent->referrer());
        }
    }

    function view_all_salary()
    {
        if(isset($_POST['search'])) 
        {
            $data['cur_date'] = date('M', strtotime($this->input->post('date'))).', '.date('Y', strtotime($this->input->post('date')));
            $month = date('m', strtotime($this->input->post('date')));
            $year = date('Y', strtotime($this->input->post('date'))); 
            $data['app_setting'] = $this->setting_model->get_all_app_setting();
            $data['all_salary_adv'] = $this->user->get_all_salary_details($month, $year);
            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/emp_payout/view_all_salary');
            $this->load->view('admin/include/footer');
        }
        else
        {
            $data['cur_date'] = date('M, Y');
            $month = date('m');
            $year = date('Y'); 
            $data['app_setting'] = $this->setting_model->get_all_app_setting();
            $data['all_salary_adv'] = $this->user->get_all_salary_details($month, $year);
            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/emp_payout/view_all_salary');
            $this->load->view('admin/include/footer');
        }
    }

    function add_salary_details()
    {
        if ($this->user->add_salary_details()) 
        {
            $this->session->set_userdata('success', "Salary Successfully Added");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Salary Added Failed");
            redirect($this->agent->referrer());
        }
    }

    function my_payout_details()
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_salary'] = $this->user->get_all_my_payout_details(user()->user_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/emp_payout/my_payout_details');
        $this->load->view('admin/include/footer');
    }



}
