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

class We_model extends CI_Model {

    /**
     * CONSTRUCTOR | LOAD DB
    */
    public function __construct() {
     parent::__construct();
     $this->load->database();
 }

    /**
     * SHOW | GET method.
     *
     * @return Response
    */
    public function show($id_cust = 0,$id_club = 0, $page = 0, $limit = 10)
    {
        if(empty($id_cust)) $id_cust=0;
        if(empty($id_club)) $id_club=0;
        if(empty($page)) $page=0;
        if(empty($limit)) $limit=10;

        $offset = ($page-1)*$limit;
        $filter_limit = " limit ".$offset.",".$limit;
        $sql = "SELECT * from customer_we where ".
        " id_customer='".$id_cust."' ".
        " and id_club='".$id_club."' order by id DESC ".$filter_limit;      
        $query = $this->db->query($sql)->result();
        return $query;
    }



    /**
     * create_user function.
     * 
     * @access public
     * @param mixed $username
     * @param mixed $email
     * @param mixed $password
     * @return bool true on success, false on failure
     */
    public function create_we($input_data) {

        date_default_timezone_set("Asia/Bangkok");
        $tgl_now = date("Y-m-d H:i:s");

        $data = array(
            'id_club' => $input_data["id_club"],
            'id_customer' => $input_data["id_customer"],
            'usia' => $input_data["usia"],
            'jenis_kelamin' => $input_data["jenis_kelamin"],
            'tinggi_badan' => $input_data["tinggi_badan"],
            'berat_badan' => $input_data["berat_badan"],
            'lemak_tubuh' => $input_data["lemak_tubuh"],
            'kadar_air' => $input_data["kadar_air"],
            'massa_otot' => $input_data["massa_otot"],
            'rating_fisik' => $input_data["rating_fisik"],
            'kebutuhan_kalori' => $input_data["kebutuhan_kalori"],
            'usia_sel' => $input_data["usia_sel"],
            'massa_tulang' => $input_data["massa_tulang"],
            'lemak_perut' => $input_data["lemak_perut"],
            'bmi' => $input_data["bmi"],
            'protein' => $input_data["protein"],
            'create_tgl' => $tgl_now,
            'photo_depan' => $input_data["photo_depan"],
            'photo_samping' => $input_data["photo_samping"],
            'keterangan' => $input_data["keterangan"]
        );

          // var_dump($data) ;
        
        $this->db->insert('customer_we', $data);

        if ($this->db->affected_rows()>0) {
            $res='OK';
        } else {
            $res='FAILED';
        }

        $arr_Result = array(
            'insertId' => $this->db->insert_id(), 
            'result' => $res);
        return json_encode($arr_Result);


        // return $this->db->insert_id(); 
        
    }


}
