application/controllers/Company.php
/* 
    * It redirects to the company page and displays all the company information
    * It also updates the company information into the database if the 
    * validation for each input field is successfully valid
    */
It redirects to the company page and displays all the company information
It also updates the company information into the database if the
validation for each input field is successfully valid
It redirects to the company page and displays all the company information It also updates the company information into the database if the validation for each input field is successfully valid
public function index()
	{  
        if(!in_array('updateCompany', $this->permission)) {
            redirect('dashboard', 'refresh');
        }
		$this->form_validation->set_rules('company_name', 'Company name', 'trim|required');
		$this->form_validation->set_rules('service_charge_value', 'Charge Amount', 'trim|integer');
		$this->form_validation->set_rules('discount', 'Discount', 'trim|integer');
		$this->form_validation->set_rules('address', 'Address', 'trim|required');
		$this->form_validation->set_rules('message', 'Message', 'trim|required');
        if ($this->form_validation->run() == TRUE) {
            $amount = $this->input->post('service_charge_value');
            $service_charge_value = number_format($amount, 2);
        	$data = array(
        		'company_name' => $this->input->post('company_name'),
        		'service_charge_value' => $service_charge_value,
        		'vat_charge_value' => 0,
				'address' => $this->input->post('address'),
        		'phone' => $this->input->post('phone'),
        		'country' => $this->input->post('country'),
        		'message' => $this->input->post('message'),
                'currency' => $this->input->post('currency')
        	);
        	$update = $this->model_company->update($data, 1);
        	if($update == true) {
        		$this->session->set_flashdata('success', 'Successfully created');
        		redirect('company/', 'refresh');
        	}
        	else {
        		$this->session->set_flashdata('errors', 'Error occurred!!');
        		redirect('company/index', 'refresh');
        	}
        }
        else {
            $this->data['currency_symbols'] = $this->currency();
        	$this->data['company_data'] = $this->model_company->getCompanyData(1);
			$this->render_template('company/index', $this->data);			
        }	
	}
public function index ( ) { if ( ! in_array ( 'updateCompany' , $ this -> permission ) ) { redirect ( 'dashboard' , 'refresh' ) ; } $ this -> form_validation -> set_rules ( 'company_name' , 'Company name' , 'trim|required' ) ; $ this -> form_validation -> set_rules ( 'service_charge_value' , 'Charge Amount' , 'trim|integer' ) ; $ this -> form_validation -> set_rules ( 'discount' , 'Discount' , 'trim|integer' ) ; $ this -> form_validation -> set_rules ( 'address' , 'Address' , 'trim|required' ) ; $ this -> form_validation -> set_rules ( 'message' , 'Message' , 'trim|required' ) ; if ( $ this -> form_validation -> run ( ) == TRUE ) { $ amount = $ this -> input -> post ( 'service_charge_value' ) ; $ service_charge_value = number_format ( $ amount , 2 ) ; $ data = array ( 'company_name' => $ this -> input -> post ( 'company_name' ) , 'service_charge_value' => $ service_charge_value , 'vat_charge_value' => 0 , 'address' => $ this -> input -> post ( 'address' ) , 'phone' => $ this -> input -> post ( 'phone' ) , 'country' => $ this -> input -> post ( 'country' ) , 'message' => $ this -> input -> post ( 'message' ) , 'currency' => $ this -> input -> post ( 'currency' ) ) ; $ update = $ this -> model_company -> update ( $ data , 1 ) ; if ( $ update == true ) { $ this -> session -> set_flashdata ( 'success' , 'Successfully created' ) ; redirect ( 'company/' , 'refresh' ) ; } else { $ this -> session -> set_flashdata ( 'errors' , 'Error occurred!!' ) ; redirect ( 'company/index' , 'refresh' ) ; } } else { $ this -> data [ 'currency_symbols' ] = $ this -> currency ( ) ; $ this -> data [ 'company_data' ] = $ this -> model_company -> getCompanyData ( 1 ) ; $ this -> render_template ( 'company/index' , $ this -> data ) ; } }
It redirects to the company page and displays all the company information
 It also updates the company information into the database if the
 validation for each input field is successfully valid
It redirects to the company page and displays all the company information It also updates the company information into the database if the validation for each input field is successfully valid
//$this->form_validation->set_rules('vat_charge_value', 'Vat Charge', 'trim|integer'); // true case // false case