<?php

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

class Servicedepartment_controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code
        $this->load->model('servicedepartment_model');
     
        $this->load->model('business_model');
        
            if($this->session->userdata('username') !== 'attendance'){
                if($this->session->userdata('role') == '' ){
            redirect('logout');
            }
        }
    }

    public function index() {
        if($this->session->userdata('role')=='' || $this->session->userdata('role')=='Sh-Users'){
            $this->load->view('login_view');
        } else {
            //echo 'here'; exit();
            $data['nav'] = 'my_business';
            $data['subnav'] = 'service_department';
            
            //get the posted values
            
            $data['business']=$this->business_model->getbusinessdetails();
            
            $data['department']=$this->servicedepartment_model->get_service_departments($this->session->userdata("businessid"));
            
            $this->load->view('includes/header', $data);
            $this->load->view('setting/service_department');
            $this->load->view('includes/footer');
            
        }
    }

    public function addservicedepartment() {
       
        $data = array(
            'service_department'=>$this->input->post('service_department'),
            'department_status'=>$this->input->post('department_status'),
            'business_id'=>$this->session->userdata('businessid')
        );

        $this->db->insert('service_department', $data);

        $data['business']=$this->business_model->getbusinessdetails();
            
        $data['department']=$this->servicedepartment_model->get_service_departments($this->session->userdata("businessid"));
        
        $this->load->view('includes/header', $data);
        $this->load->view('setting/service_department');
        $this->load->view('includes/footer');
        
    }

    public function updateservicedepartment(){

       
        $this->db->where('id_service_department =', $this->input->post('id_service_department'));
        $this->db->set('service_department', $this->input->post('service_department'));
        $this->db->set('department_status', $this->input->post('department_status'));
        $query = $this->db->update('service_department');
      
       
        $data['business']=$this->business_model->getbusinessdetails();
            
        $data['department']=$this->servicedepartment_model->get_service_departments($this->session->userdata("businessid"));
        
        $this->load->view('includes/header', $data);
        $this->load->view('setting/service_department');
        $this->load->view('includes/footer');

    }
}