<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of accountmodel
 *
 * @author BusyMan
 */
class callmodel extends CI_Model {

    //put your code here
    private $_tbl_CA = 'tbl_calls';
    private $_tbl_CREG='tbl_customer_reg';
    private $_tbl_PRG='tbl_project';

    // public function insert_amount($data) {
    //     $data['date']=date('Y-m-d',strtotime($data['date']));
    //     $this->db->insert($this->_tbl_AC, $data);
    //     return $this->db->insert_id();
    // }

    public function insert_calldetails($data) {
        $data['date']=date('Y-m-d',strtotime($data['date']));
        $this->db->insert($this->_tbl_CA, $data);
        return $this->db->insert_id();
        }

    public function GetCustomerlist($data){
        $this->db->select('tbl_customer_reg.*');
        $this->db->select('tbl_project.project_name');
        $this->db->join('tbl_project','tbl_project.project_id=tbl_customer_reg.projectcategory');    
        $query=$this->db->get_where('tbl_customer_reg', array('customerId' =>$data['customerId']));
        $result=$query->row_array();
        if(!empty($result)){
            return $result;
        }
    }

    

    public function getallcalls(){ 
    	$query=$this->db->select('*')->order_by('c_id','desc')->get($this->_tbl_CA);
    	$result=$query->result_array();
        if (!empty($result)) {
            return $result;
        }
    }


    public function callInfoById($id){
        $query=$this->db->get_where($this->_tbl_CA,array('c_id'=>$id));
        $result=$query->result_array();
        if (!empty($result)) {
            return $result;
        }
        
    }
    
    public function updateIncomeById($data)
    {
        $data['date']=date('Y-m-d',strtotime($data['date']));
        $this->db->update($this->_tbl_AC,$data,array('id'=>$data['id']));
        return $this->db->affected_rows();
    }
    
    public function deletecallByid($id)
    {
        $query=$this->db->delete($this->_tbl_CA,array('c_id'=>$id));
        return $this->db->affected_rows();
    }

    public function getCallByDate($data)
        {
             $data['fromdate']=date('Y-m-d',strtotime($data['fromdate']));
             $data['todate']=date('Y-m-d',strtotime($data['todate']));
             
             $query = $this->db->where('date BETWEEN "' . $data['fromdate'] . '" and "' . $data['todate'] . '"')
                                ->get($this->_tbl_CA);
            
            $result=$query->result_array();
            if(!empty($result)){
                return $result;
            }
        }
        

}