<?php

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

class LandCustomerRegistration extends OWN_Controller {

    function __construct() {
        parent::__construct();
        $this->admin_login_check();        
        $this->load->model('landcustomerregistrationmodel/landcustomerregistrationmodel', 'CREGModel');
        $this->load->model('incomesetupmodel/incomesetupmodel', 'incomesetupmodel');
        $this->load->model('projectnameshowmodel');
        $this->load->model('refnamesshowmodel');
    }

    public function index() {        
        $records= $this->projectnameshowmodel->getRecords();        
        $allrefs= $this->refnamesshowmodel->getRecords();
        $this->load->view('common/header');
        $this->load->view('common/menu');
        $this->load->view('admin/customer/landcustomerRegistration', ['records'=>$records, 'allrefs'=>$allrefs]);
        $this->load->view('admin/customer/index');
        $this->load->view('common/footer');
    }

    public function save_customer_info() {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $config = array(
            array(
                'field' => 'data[customerId]',
                'label' => 'Customer ID',
                'rules' => 'xss_clean|trim'
                // 'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[applicant_name]',
                'label' => 'Application Name',
                'rules' => 'required|xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[nationalid]',
                'label' => 'National Id',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[fatherName]',
                'label' => 'Father Name',
                'rules' => 'xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[motherName]',
                'label' => 'Mother Name',
                'rules' => 'xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[husbant_wifeName]',
                'label' => 'Hasbend/Wife Name',
                'rules' => 'xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[phone]',
                'label' => 'Phone',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[mobile]',
                'label' => 'Mobile',
                //'rules' => 'xss_clean|callback__check_phone|max_length[13]|min_length[11]'
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[email]',
                'label' => 'Email',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[occupation]',
                'label' => 'Occupation',
                'rules' => 'xss_clean|trim|numeric'
            ),
            array(
                'field' => 'data[presentAddress]',
                'label' => 'Present Address',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[permanentAddress]',
                'label' => 'Permanent Address',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[birthdate]',
                'label' => 'Brith date',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[nationality]',
                'label' => 'Nationality',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[religion]',
                'label' => 'Religion',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[gender]',
                'label' => 'Gender',
                'rules' => 'trim|xss_clean|numeric'
            ),
            array(
                'field' => 'data[nomineeName]',
                'label' => 'Nominee Name',
                'rules' => 'required|xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[relationship]',
                'label' => 'Relationship',
                'rules' => 'xss_clean|trim|alpha_spaces'
            ),
            array(
                'field' => 'data[address]',
                'label' => 'Address',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[office]',
                'label' => 'Office',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[passportNumber]',
                'label' => 'Passport Number',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[tinNo]',
                'label' => 'tinNo',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[nominee_mobile]',
                'label' => 'Nominee Mobile',
                //'rules' => 'xss_clean|callback__check_phone|max_length[13]|min_length[11]'
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[nominee_phone]',
                'label' => 'nominee phone',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[nominee_email]',
                'label' => 'Nominee Email',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[part]',
                'label' => 'Part',
                'rules' => 'xss_clean|trim'
            ),
            array(
                'field' => 'data[projectCategory]',
                'label' => 'Project Category',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[projectBlockNo]',
                'label' => 'Block No',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[plotNo]',
                'label' => 'plotNo',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[roadNo]',
                'label' => 'Road No',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[plote_size]',
                'label' => 'plote size',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[plote_face]',
                'label' => 'ploat face',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[payment_type]',
                'label' => 'Payment Type',
                'rules' => 'required|xss_clean|trim'
            ),
            array(
                'field' => 'data[total_cost]',
                'label' => 'Total Cost',
                'rules' => 'required|trim|xss_clean|numeric'
            ),
            array(
                'field' => 'data[down_payment]',
                'label' => 'Down Payment',
                'rules' => 'required|trim|xss_clean|numeric'
            ),
            array(
                'field' => 'data[dues]',
                'label' => 'Dues',
                'rules' => 'required|trim|xss_clean'
            ),
            array(
                'field' => 'data[date]',
                'label' => 'Date',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[installment_step]',
                'label' => 'Installment Step',
                'rules' => 'required|trim|xss_clean|numeric'
            ),
            array(
                'field' => 'data[kro_num]',
                'label' => 'Kromik Number ',
                'rules' => 'trim|xss_clean'
            ),
            array(
                'field' => 'data[customer_ref]',
                'label' => 'Reference Name',
                'rules' => 'trim|xss_clean|required'
            ),
        );


        $this->form_validation->set_rules($config);
        if ($this->form_validation->run() == FALSE) {
            $this->load->view('common/header');
            $this->load->view('common/menu');
            $this->load->view('admin/customer/landcustomerRegistration');
            $this->load->view('common/footer');
        } else {
            $data = $this->input->post('data', TRUE);
            $this->load->library('upload', $config);
            $config['upload_path'] = './uploadimage/customerImage/';
            $config['allowed_types'] = 'png|jpeg|jpg|gif';
            $config['max_size'] = '800';
            $config['max_width'] = '800';
            $config['max_height'] = '600';
            $udata = '';
            $udata1 = '';

            $this->upload->initialize($config);

            if ($this->upload->do_upload('photo')) {
                $udata = array('upload_data' => $this->upload->data());
                $data['photo'] = "uploadimage/customerImage/" . $udata['upload_data']['file_name'];
            }

            if ($this->upload->do_upload('nominee_photo')) {
                $udata1 = array('upload_data1' => $this->upload->data());
                $data['nominee_photo'] = "uploadimage/customerImage/" . $udata1['upload_data1']['file_name'];
            }


            //$data['applicant_name'] = implode(',', $data['applicant_name']) . ',';
            //-----------generate customerId---------------------------
            $new_stt = sprintf('%02d', $data['religion']);
            $datae = date('Y');
            //remove comment line if customer id is auto
            $data['customerId'] = $datae . "-" . $new_stt . "-" . customeridGenerate();
            //-------------------------------------------------------------------
            //----------------------GENERATE user_name AND user_password-----------------
            $data['user_password'] = strtoupper(substr($data['applicant_name'], -3)) . $data['customerId'];
            $data['user_name'] = "customer" . strtolower(substr($data['applicant_name'], -3));     // take letter from first side : substr($data['applicant_name'],0,2)
            //---------------------------------------------------------------------------
            //echo "<pre>";print_r($data);die();
            if (!empty($data)) {
                $execution = $this->CREGModel->insert_customer_info($data);

                if (!empty($execution)) {
                    $message['message'] = "Customer Registration Complete.</br> Customer Id is = " . $data['customerId'] . " , UserName is = " . $data['user_name'] . " , Password is = " . $data['user_password'];
                    $this->session->set_userdata($message);


                   $result = $this->incomesetupmodel->GetCustomerlist($data);
                    
                    //send email confirmation
                    // $this->load->library('email');
                    // $config = array(
                    //     'protocol'  => 'smtp',
                    //     'smtp_host' => 'ssl://smtp.gmail.com',
                    //     'smtp_port' => 465,
                    //     'smtp_user' => 'mail.hasanhomesltd@gmail.com',
                    //     'smtp_pass' => 'Hasan@007',
                    //     'mailtype'  => 'html',
                    //     'charset'   => 'utf-8'
                    // );
                    // $this->email->initialize($config);
                    // $this->email->set_mailtype("html");
                    // $this->email->set_newline("\r\n");

                    // $this->email->from('mail.hasanhomesltd@gmail.com', 'HasanHomes');
                    // $this->email->to("".$data['email']."");
                    // //$this->email->cc('mail@mail.com');
                    // $this->email->subject('Customer Reg. Confirmation');
                    // $this->email->message("Congratulation! Your Plot booking process is Complete. Your CustomerId : " . $data['customerId'] . " . Thank You. " .$result['project_name']."  .This is an automated Email. Please don't reply.");
                    // if($this->email->send()){
                    //     $msg="Confirmation Mail Send";
                    // }
                    // else{
                    //     $msg="Mail Not Send";
                    // }
                    
                    
                    //send email confirmation



                    //send sms api integration

                    // $to = "".$data['mobile']."";
                    // $token = "cc92332d1f38e1817dc20cdd3f77bd18";
                    // $message = "Dear Customer, Your Ccare Registration is Complete. Your UserName is = " . $data['user_name'] . " and Password is = " . $data['user_password']."";
                    
                    
                    
                    
                    
                    $to = "".$data['mobile']."";
                    $token = "cc92332d1f38e1817dc20cdd3f77bd18";
                    $message = "Congratulation! Your Plot booking process is Complete. Your Temporary CustomerId : " . $data['customerId'] . " . Thank You. " .$result['project_name']."";

                    $url = "http://api.greenweb.com.bd/api.php";


                    $data= array(
                    'to'=>"$to",
                    'message'=>"$message",
                    'token'=>"$token"
                    ); // Add parameters in key value
                    $ch = curl_init(); // Initialize cURL
                    curl_setopt($ch, CURLOPT_URL,$url);
                    curl_setopt($ch, CURLOPT_ENCODING, '');
                    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
                    $smsresult = curl_exec($ch);
                    
                    //send sms api integration
                    
                    
                    redirect('admin/landcustomerRegistration/ViewLandCustomer', 'refresh');
                    // $this->load->view('common/header');
                    // $this->load->view('common/menu');
                    //$this->load->view('admin/customer/ViewLandCustomer',$data);
                    //$this->load->view('common/footer');


                    

                } else {
                    $errormessage['errormessage'] = "Customer Registration Not Complete";
                    $this->session->set_userdata($errormessage);
                    redirect('admin/landcustomerRegistration/ViewLandCustomer', 'refresh');
                }
            } else {
                $errormessage['errormessage'] = "Customer Registration Information Missing";
                $this->session->set_userdata($errormessage);
                redirect('admin/landcustomerRegistration/ViewLandCustomer', 'refresh');
            }
        }
    }

    public function referenceInfo($type) {
        if (!empty($type)) {
            $output = '';
            $data = $this->CREGModel->getAllReferenceInfo($type);
            if ($type == 1) {
                $output .= '<label class="control-label" for="form-field-1">Reference Name &nbsp; </label>
                            <select name="" class="form-control col-xs-10 col-sm-12" id="ref_name_2" onchange="selectRefName()">
                                <option selected disabled>Select Reference Name</option>';
                foreach ($data as $value) {
                    $output .='<option value="' . $value['customerId'] . '">' . $value['applicant_name'] . '</option>';
                }
                $output .='</select>';
                echo $output;
            } else if ($type == 2) {
                $output .= '<label class="control-label" for="form-field-1">Reference Name &nbsp; </label>
                            <select name="data[customer_ref]" class="form-control col-xs-10 col-sm-12" id="ref_name_2" onchange="selectRefName()">
                                <option selected disabled>Select Reference Name</option>';
                foreach ($data as $value) {
                    $output .='<option value="' . $value['userId'] . '">' . $value['userId'] ." - ".$value['userName'] . '</option>';
                }
                $output .='</select>';
                echo $output;
            }
        }
    }
    
    public function viewlastcall(){
        $customerId = '027';
        $data['customerlastcall'] = $this->CREGModel->getcustomerlastcall($customerId);
        echo $data['customerlastcall']['description'];
    }

    public function ViewLandCustomer() {

        $data['allLandcustomer'] = $this->CREGModel->getlandCustomer();
        
        //$adminLebel=$this->session->userdata('admin_level');
        // echo($data['allLandcustomer']);die();
        if (!empty($data['allLandcustomer'])) {
            $this->load->view('common/header');
            $this->load->view('common/menu');
            $this->load->view('admin/customer/viewlandCustomer', $data);
            $this->load->view('common/footer');
        } else {
            $errormessage['errormessage'] = "There Are No Customer availble";
            $this->session->set_userdata($errormessage);
            $this->load->view('common/header');
            $this->load->view('common/menu');
            $this->load->view('dashbord');
            $this->load->view('common/footer');
        }
    }

    public function viewProfile($id) {
        $admin_id = $this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id != "")) {
            $data['customerById'] = $this->CREGModel->getcustomerById($id);
            //new added
            $data['basic_info'] = $this->CREGModel->getcustomerByIdsinview($id);
            $customer_id = $data['basic_info']['customerId'];
            $data['allincome'] = $this->CREGModel->getincomeByCustomerIds($customer_id);
            $data['total_cost'] = $data['basic_info']['total_cost'];

            if (!empty($data['customerById'])) {
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('admin/customer/landcustomerProfile', $data);
                $this->load->view('common/footer');
            } else {
//                $errormessage['errormessage']="No profile Found";
//                $this->session->set_userdata($errormessage);
                redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
            }
        } else {
            redirect(base_url('admin', 'refresh'));
        }
    }    
    public function viewCommission($id) {
        $admin_id = $this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id != "")) {
            $data['customerById'] = $this->CREGModel->getcustomerById($id);
            //new added
            $data['basic_info'] = $this->CREGModel->getcustomerByIdsinview($id);
            $customer_id = $data['basic_info']['customerId'];
            $data['allpercents'] = $this->CREGModel->getPercentsById($customer_id);
            $data['allcommission'] = $this->CREGModel->getCommissionById($customer_id);
            $data['allincentive'] = $this->CREGModel->getIncentiveById($customer_id);
            $data['total_cost'] = $data['basic_info']['com_emp'];
            $data['total_incentive'] = $data['basic_info']['incentive'];

            if (!empty($data['customerById'])) {
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('admin/customer/viewCommission', $data);
                $this->load->view('common/footer');
            } else {
//                $errormessage['errormessage']="No profile Found";
//                $this->session->set_userdata($errormessage);
                redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
            }
        } else {
            redirect(base_url('admin', 'refresh'));
        }
    }

    public function delete_customer($id) {
        $adminLebel = $this->session->userdata('admin_level');
        $admin_id = $this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id != "")) {
            if ($adminLebel == 1) {
                $editdata = $this->CREGModel->getcustomerById($id);
                if (!empty($editdata)) {
                    $dlt_file = $editdata['photo'];
                    if (file_exists($dlt_file)) {
                        unlink($dlt_file);
                    }

                    $dlt_file1 = $editdata['nominee_photo'];
                    if (file_exists($dlt_file1)) {
                        unlink($dlt_file1);
                    }
                    $execution = $this->CREGModel->deletecustomerById($id);
                    if (!empty($execution)) {
                        $message['message'] = "Customer Info deleted";
                        $this->session->set_userdata($message);
                        redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                    } else {
                        $errormessage['errormessage'] = "Customer Not Deleted";
                        $this->session->set_userdata($errormessage);
                        redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                    }
                } else {
                    $errormessage['errormessage'] = "Customer Not Found";
                    $this->session->set_userdata($errormessage);
                    redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                }
            } else {
                $errormessage['errormessage'] = "You Not Permitted For Deleting Customer";
                $this->session->set_userdata($errormessage);
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('dashbord');
                $this->load->view('common/footer');
            }
        } else {
            redirect(base_url('admin', 'refresh'));
        }
    }

    public function edit_customer($Id) {
        $records= $this->projectnameshowmodel->getRecords();        
        $allrefs= $this->refnamesshowmodel->getRecords();
        $adminLebel = $this->session->userdata('admin_level');
        $admin_id = $this->session->userdata('admin_id');
        if ((!empty($admin_id)) || ($admin_id != "")) {
            if ($adminLebel == 1) {
                $data['customerById'] = $this->CREGModel->getcustomerById($Id);
                if (!empty($data['customerById'])) {
                    $this->load->view('common/header');
                    $this->load->view('common/menu', ['records'=>$records, 'allrefs'=>$allrefs]);
                    $this->load->view('admin/customer/edit_landCustome', $data);
                    $this->load->view('common/footer');
                } else {
                    redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                }
            } else {
                $errormessage['errormessage'] = "You Not Permitted For Editing Customer";
                $this->session->set_userdata($errormessage);
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('dashbord');
                $this->load->view('common/footer');
            }
        } else {
            redirect(base_url('admin', 'refresh'));
        }
    }

    public function update_customer() {
        $adminLebel = $this->session->userdata('admin_level');
        $admin_id = $this->session->userdata('admin_id');
        $Id = $this->input->post('id', TRUE);
        if ((!empty($admin_id)) || ($admin_id != "")) {
            if ($adminLebel == 1) {
                if (isset($_POST['btnUpdate'])) {
                    $this->load->helper(array('form', 'url'));
                    $this->load->library('form_validation');
                    $config = array(
                        array(
                            'field' => 'data[applicant_name]',
                            'label' => 'Application Name',
                            'rules' => 'required|xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[nationalid]',
                            'label' => 'National Id',
                            'rules' => 'trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[fatherName]',
                            'label' => 'Father Name',
                            'rules' => 'xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[motherName]',
                            'label' => 'Mother Name',
                            'rules' => 'xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[husbant_wifeName]',
                            'label' => 'Hasbend/Wife Name',
                            'rules' => 'xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[phone]',
                            'label' => 'Phone',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[mobile]',
                            'label' => 'Mobile',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[email]',
                            'label' => 'Email',
                            'rules' => 'trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[occupation]',
                            'label' => 'Occupation',
                            'rules' => 'xss_clean|trim|numeric'
                        ),
                        array(
                            'field' => 'data[presentAddress]',
                            'label' => 'Present Address',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[permanentAddress]',
                            'label' => 'Permanent Address',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[birthdate]',
                            'label' => 'Brith date',
                            'rules' => 'trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[nationality]',
                            'label' => 'Nationality',
                            'rules' => 'trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[religion]',
                            'label' => 'Religion',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[gender]',
                            'label' => 'Gender',
                            'rules' => 'trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[nomineeName]',
                            'label' => 'Nominee Name',
                            'rules' => 'required|xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[relationship]',
                            'label' => 'Relationship',
                            'rules' => 'xss_clean|trim|alpha_spaces'
                        ),
                        array(
                            'field' => 'data[address]',
                            'label' => 'Address',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[office]',
                            'label' => 'Office',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[passportNumber]',
                            'label' => 'Passport Number',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[tinNo]',
                            'label' => 'tinNo',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[nominee_mobile]',
                            'label' => 'Nominee Mobile',
                            //'rules' => 'xss_clean|max_length[13]|min_length[11]'
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[nominee_phone]',
                            'label' => 'nominee phone',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[nominee_email]',
                            'label' => 'Nominee Email',
                            'rules' => 'trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[part]',
                            'label' => 'Part',
                            'rules' => 'xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[projectCategory]',
                            'label' => 'Project Category',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[projectBlockNo]',
                            'label' => 'Block No',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[plotNo]',
                            'label' => 'plotNo',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[roadNo]',
                            'label' => 'Road No',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[plote_size]',
                            'label' => 'plote size',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[plote_face]',
                            'label' => 'ploat face',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[payment_type]',
                            'label' => 'Payment Type',
                            'rules' => 'required|xss_clean|trim'
                        ),
                        array(
                            'field' => 'data[total_cost]',
                            'label' => 'Total Cost',
                            'rules' => 'required|trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[down_payment]',
                            'label' => 'Down Payment',
                            'rules' => 'required|trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[dues]',
                            'label' => 'Dues',
                            'rules' => 'required|trim|xss_clean'
                        ),
                        array(
                            'field' => 'data[installment_step]',
                            'label' => 'Installment Step',
                            'rules' => 'required|trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[incentive]',
                            'label' => 'com Incentive',
                            'rules' => 'trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[com_emp]',
                            'label' => 'com emp',
                            'rules' => 'trim|xss_clean|numeric'
                        ),
                        array(
                            'field' => 'data[kro_num]',
                            'label' => 'Kromik Number ',
                            'rules' => 'trim|xss_clean'
                        )
                    );
                    $this->form_validation->set_rules($config);
                    if ($this->form_validation->run() == FALSE) {
                        $data['customerById'] = $this->CREGModel->getcustomerById($Id);
                        $this->load->view('common/header');
                        $this->load->view('common/menu');
                        $this->load->view('admin/customer/edit_landCustome', $data);
                        $this->load->view('common/footer');
                    } else {

                        $data = $this->input->post('data', TRUE);
                        $data['id'] = $this->input->post('id', TRUE);
                        $this->load->library('upload', $config);
                        $config['upload_path'] = './uploadimage/customerImage/';
                        $config['allowed_types'] = 'png|jpeg|jpg|gif';
                        $config['max_size'] = '800';
                        $config['max_width'] = '800';
                        $config['max_height'] = '600';
                        $udata = '';
                        $udata1 = '';

                        $this->upload->initialize($config);

                        if ($this->upload->do_upload('photo')) {
                            $udata = array('upload_data' => $this->upload->data());
                            if (empty($udata['upload_data']['file_name'])) {
                                unset($udata1['upload_data1']['file_name']);
                            } else {
                                $data['photo'] = "uploadimage/customerImage/" . $udata['upload_data']['file_name'];
                            }
                        }

                        if ($this->upload->do_upload('nominee_photo')) {
                            $udata1 = array('upload_data1' => $this->upload->data());
                            if (empty($udata1['upload_data1']['file_name'])) {
                                unset($udata1['upload_data1']['file_name']);
                            } else {
                                $data['nominee_photo'] = "uploadimage/customerImage/" . $udata1['upload_data1']['file_name'];
                            }
                        }
                        //echo '<pre>';print_r($udata1);die();

                        $execution = $this->CREGModel->updateCustomerById($data);
                        if (!empty($execution)) {
                            $message['message'] = "Customer Info Updated";
                            $this->session->set_userdata($message);
                            redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                        } else {
                            $errormessage['errormessage'] = "Customer Info Not Updated";
                            $this->session->set_userdata($errormessage);
                            redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                        }
                    }
                } else {
                    redirect(admin_url() . '/landcustomerRegistration/ViewLandCustomer', 'refresh');
                }
            } else {
                $errormessage['errormessage'] = "You Not Permitted For Editing Customer";
                $this->session->set_userdata($errormessage);
                $this->load->view('common/header');
                $this->load->view('common/menu');
                $this->load->view('dashbord');
                $this->load->view('common/footer');
            }
        } else {
            redirect(base_url('admin', 'refresh'));
        }
    }

}
