<?php

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

class Fee extends Admin_Controller
{

    public function __construct()
    {
        parent::__construct();
		 if(user_type()!="admin"){
		     redirect('Dashboard', 'refresh');
		  }
        $this->load->library('form_validation');
        $this->load->model('Fee_model');
    }


    public function index()
    {
        $this->load->view('theme/fee/fee');
    }


    public function save()
    {

    // Set the Form Data
        $data = array(
            array(
                'cost_name' => 'cost-1',
                'from_amount' => '1',
                'to_amount' => '25000',
                'fee' => $this->input->post("cost-1", true)
            ),
            array(
                'cost_name' => 'cost-2',
                'from_amount' => '25001',
                'to_amount' => '50000',
                'fee' => $this->input->post("cost-2", true)
            ),
            array(
                'cost_name' => 'cost-3',
                'from_amount' => '50001',
                'to_amount' => '75000',
                'fee' => $this->input->post("cost-3", true)
            ),
            array(
                'cost_name' => 'cost-4',
                'from_amount' => '75001',
                'to_amount' => '100000',
                'fee' => $this->input->post("cost-4", true)
            ),
            array(
                'cost_name' => 'cost-5',
                'from_amount' => '100001',
                'to_amount' => '125000',
                'fee' => $this->input->post("cost-5", true)
            ),
            array(
                'cost_name' => 'cost-6',
                'from_amount' => '125001',
                'to_amount' => '150000',
                'fee' => $this->input->post("cost-6", true)
            ),
            array(
                'cost_name' => 'cost-7',
                'from_amount' => '150001',
                'to_amount' => '200000',
                'fee' => $this->input->post("cost-7", true)
            ),
            array(
                'cost_name' => 'cost-8',
                'from_amount' => '200001',
                'to_amount' => '250000',
                'fee' => $this->input->post("cost-8", true)
            ),
            array(
                'cost_name' => 'cost-9',
                'from_amount' => '250001',
                'to_amount' => '300000',
                'fee' => $this->input->post("cost-9", true)
            ),
            array(
                'cost_name' => 'cost-10',
                'from_amount' => '300001',
                'to_amount' => '400000',
                'fee' => $this->input->post("cost-10", true)
            ),
            array(
                'cost_name' => 'cost-11',
                'from_amount' => '400001',
                'to_amount' => '500000',
                'fee' => $this->input->post("cost-11", true)
            ),
            array(
                'cost_name' => 'cost-12',
                'from_amount' => '500001',
                'to_amount' => '600000',
                'fee' => $this->input->post("cost-12", true)
            ),
            array(
                'cost_name' => 'cost-13',
                'from_amount' => '600001',
                'to_amount' => '700000',
                'fee' => $this->input->post("cost-13", true)
            ),
            array(
                'cost_name' => 'cost-14',
                'from_amount' => '700001',
                'to_amount' => '800000',
                'fee' => $this->input->post("cost-14", true)
            ),
            array(
                'cost_name' => 'cost-15',
                'from_amount' => '800001',
                'to_amount' => '900000',
                'fee' => $this->input->post("cost-15", true)
            ),
            array(
                'cost_name' => 'cost-16',
                'from_amount' => '900001',
                'to_amount' => '1000000',
                'fee' => $this->input->post("cost-16", true)
            ),
            array(
                'cost_name' => 'cost-17',
                'from_amount' => '1000000',
                'to_amount' => '99999999999',
                'fee' => $this->input->post("cost-17", true)
            )

        );

            //---Insert Or Update---//
            if ($this->Fee_model->get_num_rows() > 0) {
                //---Do Update---//
                if ($this->db->update_batch('cost', $data,'cost_name')) {
                    $this->session->set_flashdata('success', 'Data Updated Sucessfully');
                    redirect('Fee', 'refresh');
                } else {
                    $this->session->set_flashdata('error', 'Update Failed !');
                    redirect('Fee', 'refresh');
                }
            } else {
                //---Do Insert---//
                if ($this->db->insert_batch('cost', $data)) {
                    $this->session->set_flashdata('success', 'Data Updated Sucessfully');
                    redirect('Fee', 'refresh');
                } else {
                    $this->session->set_flashdata('error', 'Update Failed !');
                    redirect('Fee', 'refresh');
                }
            }
        }
    
}