<?php

class Datasheet_model extends CI_Model {
    var $mdb;

    public function __construct() {
        parent::__construct();
        $this->mdb = $this->load->database('mdb', TRUE);
    }


    
    public function load_anm($_user_level) {
        $this->mdb->select('master_area_create_by_super.region_code, master_user_details.user_name');
        $this->mdb->from('master_area_create_by_super');
        $this->mdb->join('master_login_user', 'master_area_create_by_super.region_code = master_login_user.create_region_id', 'INNER');
        $this->mdb->join('master_user_details', 'master_user_details.user_login_id = master_login_user.user_login_id', 'INNER');
        $this->mdb->where('master_area_create_by_super.region_level', $_user_level);
        return $this->mdb->get()->result_array();
    }

    public function load_asha($_region_code) {
        $this->mdb->select('master_area_create_by_super.region_code, master_user_details.user_name');
        $this->mdb->from('master_area_create_by_super');
        $this->mdb->join('master_login_user', 'master_area_create_by_super.region_code = master_login_user.create_region_id', 'INNER');
        $this->mdb->join('master_user_details', 'master_user_details.user_login_id = master_login_user.user_login_id', 'INNER');
        $this->mdb->where('master_area_create_by_super.region_code_super', $_region_code);
        return $this->mdb->get()->result_array();
    }
    
    public function show_data($_region_code) {
        $this->mdb->select('mira_house.auto_id as house_id,mira_women.women_id,mira_house.house_head_name,mira_child.child_id,mira_house.house_number, mira_women.name, mira_women.husband, mira_child.child_name, mira_child.actual_register_date');
        $this->mdb->from('mira_house');
        $this->mdb->join('mira_women', 'mira_house.auto_id = mira_women.house_id', 'LEFT');
        $this->mdb->join('mira_child', 'mira_women.women_id = mira_child.women_id', 'LEFT');
        $this->mdb->where('mira_house.region_code', $_region_code);
         $this->mdb->where('mira_child.women_id >', 0);
        return $this->mdb->get()->result_array();
        }



    public function show_house_data($_region_code) {
        $this->mdb->select('mira_house.auto_id as house_id,mira_house.house_head_name,mira_house.house_number, mira_house.total_family_member,mira_house.married_women,mira_house.unmarried_women, mira_house.actual_register_date');
        $this->mdb->from('mira_house');
        $this->mdb->where('mira_house.region_code', $_region_code);
        return $this->mdb->get()->result_array();
    }
    
    public function show_women_data($_region_code) {
        $this->mdb->select('mira_women.women_id,mira_house.house_head_name,mira_house.house_number, mira_women.name,mira_women.husband,mira_women.age, mira_women.actual_register_date');
        $this->mdb->from('mira_house');
        $this->mdb->join('mira_women', 'mira_house.auto_id = mira_women.house_id', 'LEFT');
        $this->mdb->where('mira_women.region_code', $_region_code);
        return $this->mdb->get()->result_array();
    }

        public function update_date_Old($house_id , $child_id, $women_id, $actual_register_date) {
            $house_data= array(
                'actual_register_date' => $actual_register_date,
                'update_status'=>1
            );

            $women_data= array(
                'actual_register_date' => $actual_register_date ,
                'update_status'=>1
            );


            $child_data= array(
                'actual_register_date' => $actual_register_date ,
                'update_status'=>1
            );

            
            $this->mdb->where('auto_id' , $house_id);
            $this->mdb->update('mira_house' , $house_data);

            $this->mdb->where('child_id' , $child_id);
            $this->mdb->update('mira_child' , $child_data);

            $this->mdb->where('women_id' , $women_id);
            $this->mdb->update('mira_women' , $women_data);



           
}

      public function update_date($house_id, $child_id, $women_id, $actual_register_date) {
       
        if($house_id>0)
        {
        $house_data = array(
            'actual_register_date' => $actual_register_date,
            'update_status' => 1
        );
        $this->mdb->where('auto_id', $house_id);
        $this->mdb->update('mira_house', $house_data);
        }
        
        
        if($women_id>0)
        {
        $women_data = array(
            'actual_register_date' => $actual_register_date,
            'update_status' => 1
        );
        $this->mdb->where('women_id', $women_id);
        $this->mdb->update('mira_women', $women_data);
        }
        
        if($child_id>0)
        {
           $child_data = array(
            'actual_register_date' => $actual_register_date,
            'update_status' => 1
        ); 
           
        $this->mdb->where('child_id', $child_id);
        $this->mdb->update('mira_child', $child_data);
        }
        


        


        
    }

}


        
        // public funtion update_date($house_id, $child_id, $women_id){
        //    $data = array(
        //     'actual_register_date' => $actual_register_date;
        //    );
        //    $this->mdb->where('house_id', $house_id);
        // $this->mdb->where('child_id', $child_id);
        // $this->mdb->where('women_id', $women_id);
        //    $this->mdb->update('mira_house', 'mira_child', 'mira_women'  $data);
        //     }

        // $child_data= array(
        //     'actual_register_date' => $actual_register_date
        // );

        // $women_data= array(
        //     'actual_register_date' => $actual_register_date
        // );


        // $this->mdb->where('child_id' , $child_id);
        // $this->mdb->update('mira_child' , $child_data);

        // $this->mdb->where('women_id' , $women_id);
        // $this->mdb->update('mira_women' , $women_data);


