<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Akrsp_model1 extends CI_Model {
//admin loging
function login($var)
{
$this->db->where($var);
$query=$this->db->get('njobn_users');
if($query->num_rows()==1)
{
return $query->result();
}
else
{
$this->session->set_flashdata('error_msg', 'Wrong Username And Password');
redirect('welcome/index');
}
}
/*CAREER ADVICE BLOG*/
		//code for to show skills grid
		public function read_blogs_record()
		{
			$query=$this->db->get('blogs');
			return $query->result();
		}
		
		//insert jobscategory
		public function insert_blogcategory_record($var)
		{
			$query=$this->db->insert('blogs_category',$var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		public function read_blog_category_record($pass)
		{
		
			$this->db->where($pass);
			$query=$this->db->get('blogs_category');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}	
		
		//code for to read jobscategory
		public function read_blogscategory_record()
		{
			$query=$this->db->get('blogs_category');
			return $query->result();			
		}
		
		function delete_blogs_category($table, $id)
		{
			$this->db->where('blogs_cat_id',$id);
			$query = $this->db->delete($table);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		public function update_blog_record($id, $var)
		{	
			$this->db->where('blog_id', $id);
			$query=$this->db->update('blogs', $var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
			
		}
		
		public function read_viewblogscategory_record($pass)
		{
			
			$this->db->where($pass);
			$query=$this->db->get('blogs_category');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		
		public function insert_blog_add_record($var)
		{
			$query=$this->db->insert('blogs', $var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		function delete_blog($table,$id)
		{
			$this->db->where('blog_id',$id);
			$query = $this->db->delete($table);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		public function read_viewblog_record($pass)
		{
		
			$this->db->where($pass);
			$query=$this->db->get('blogs');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		
		public function read_blog_post_record($pass)
		{
		
			$this->db->where($pass);
			$query=$this->db->get('blogs');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		
		public function update_blogcategory_record($id, $var)
		{	
			$this->db->where('blogs_cat_id', $id);
			$query=$this->db->update('blogs_category', $var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
			
		}
		
		public function read_blog_cat_record()
		{
			$query=$this->db->get('blogs_category');
			return $query->result();
		}
		
		
		public function read_blog_record()
		{
			$query=$this->db->get('blogs');
			return $query->result();
		}
		
		public function read_blog_record_by_cat($id)
		{
			$this->db->where('blog_category_id', $id);
			$query=$this->db->get('blogs');
			return $query->result();
		}
		
		public function read_blog_by_id($id) 
		{
			$this->db->where('blog_id', $id);
			$query=$this->db->get('blogs');
			return $query->result();
		}
//web user login
function user_login($var)
{
$this->db->where($var);
$query=$this->db->get('njobn_webusers');
if($query->num_rows()==1)
{
return $query->result();
}
else
{
return false;
}
}

public function insert_consumer_record($var)
{
$query=$this->db->insert('consumer',$var);
if($query)
{
return true;
}
else
{
return false;
}

}
public  function inactive_consumer_record($cid)
{	

$this->db->where('consumer_id',$cid);
$query=$this->db->get('consumer');
$b=$query->row();
if($b->status!=1)
{
$a=array('status'=>1);
$this->db->where('consumer_id',$cid);
$this->db->update('consumer',$a);
return 1;
}
else
{
return false;
}
}

public function read_consumer_record2()
{

$this->db->where('status' ,0);	
$query=$this->db->get('consumer');
return $query->result();


}
public function read_consumer_record()
{


$query=$this->db->get('consumer');
return $query->result();


}


//active code
public function active_consumer_record($cid)
{	


$this->db->where('consumer_id',$cid);
$query=$this->db->get('consumer');
$b=$query->row();

if($b->status!=0)
{
$a=array('status'=>0);
$this->db->where('consumer_id',$cid);
$this->db->update('consumer',$a);
return 0;
}
else
{
return false;
}
}	



public function read_con_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('consumer');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}

public function update_consumer_record($id,$var)
{	
$this->db->where('consumer_id', $id);
$query=$this->db->update('consumer', $var); 
if($query)
{

return true;
}
else
{
return false;
}

}
public function delete_consumer_record($cid)
{	


$this->db->where('consumer_id',$cid);
$query=$this->db->get('consumer');
$b=$query->row();

if($b->status==0)
{
$a=array('status'=>1);
$this->db->where('consumer_id',$cid);
$this->db->update('consumer',$a);
return 0;
}
if($b->status==2)
{		

return 2;
}		
if($b->status==1)
{
$a=array('status'=>0);
$this->db->where('consumer_id',$cid);
$this->db->update('consumer',$a);
return 0;
return 1;
}
}


public function read_consumer_record1()
{	$region=array('region_id'=>$this->session->userdata('region_id'));
$this->db->where($region);
$query=$this->db->get('consumer');
return $query->result();
}

//code for to get data from users table
public function read_user_record()
{
$query=$this->db->get('njobn_users');
return $query->result();

}
public function read_customer_record()
{
$query=$this->db->get('customer');
return $query->result();

}

//delte user code
function del_rec($id)
{
$this->db->where('user_id',$id);
$query=$this->db->delete('njobn_users');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="user";';
echo '</script>';
}
}
//code for to dlete page
function del_page($id)
{
$this->db->where('id',$id);
$query=$this->db->delete('pages');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="cms_pages";';
echo '</script>';
}
}

function del_customer($id)
{
$this->db->where('id',$id);
$query=$this->db->delete('customer');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="customer";';
echo '</script>';
}
}

public function insert_user_record($var)
{
$query=$this->db->insert('njobn_users',$var);
if($query)
{
return true;
}
else
{
return false;
}
}

public function insert_customer_record($var)
{
$query=$this->db->insert('customer',$var);
if($query)
{
return true;
}
else
{
return false;
}
}

//code for drodown
function get_dropdown_list()
{
$this->db->from('njobn_group');
$this->db->order_by('group_name');
$result = $this->db->get();
$return = array();
if($result->num_rows() > 0) {
foreach($result->result_array() as $row) {
$return[$row['group_id']] = $row['group_name'];
}
}

return $return;
} 
//code for to read data for edit user
public function read_user1_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_users');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	

//code for to show dat on viewjob catgory
public function read_viewjobscategory_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_jobs_category');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	
//code for to read data for edit jobcategory
public function read_job_category_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_jobs_category');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	
//code for to read data for edit skill
public function read_editskill_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('skills');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	

//code for to read data for edit product
public function read_product2_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('product');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	
public function read_testimonials2_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_testimonials');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}

public function read_customer1_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('customer');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to edit data of edit user section
public function update_user_record($id,$var)
{	
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_users', $var);
if($query)
{
return true;
}
else
{
return false;
}
}

public function upload_profile_image($id,$var)
{	
$this->db->where('candidate_id', $id);
$query=$this->db->update('njobn_candidate', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to upload employee logo
public function upload_profile_imageemp($id,$var)
{	
$this->db->where('employee_id', $id);
$query=$this->db->update('njobn_employee', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code to change the com[pany lgo
public function upload_com_logo($id,$var)
{	
$this->db->where('created_by', $id);
$query=$this->db->update('njobn_jobdetails', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
public function update_address_can($id,$var)
{	
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}

//code for to edit jobcaegory eidt form
public function update_sasasas_record($id,$var)
{	
$this->db->where('jobs_category_id', $id);
$query=$this->db->update('njobn_jobs_category', $var);
if($query)
{
return true;
}
else
{
return false;
}

}
//code for to edit data of edit customer section
public function update_customer_record($id,$var)
{	
$this->db->where('id', $id);
$query=$this->db->update('customer', $var);
if($query)
{
return true;
}
else
{
return false;
}

}	
//code for to read privaliges
public function read_privileges_record()
{


$query=$this->db->get('njobn_privileges');
return $query->result();

}	
//code for to read jobscategory
public function read_jobscategory_record()
{


$query=$this->db->get('njobn_jobs_category');
return $query->result();

}
//code for to delete user
function del_pre($id)
{
$this->db->where('privilege_id',$id);
$query=$this->db->delete('njobn_privileges');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="privileges";';
echo '</script>';
}
}
//insert privillges
public function insert_privillges_record($var)
{
$query=$this->db->insert('njobn_privileges',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//insert jobscategory
public function insert_jobscategory_record($var)
{
$query=$this->db->insert('njobn_jobs_category',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to read groups
public function read_groups_record()
{


$query=$this->db->get('njobn_group');
return $query->result();

}	
//code for to delete group
function del_groups($id)
{
//first check already exixt recorde in jobs destils page
$this->db->where('user_id',$id);
$query1 = $this->db->get('njobn_users');
if($query1->num_rows() ==0)
{
$this->db->where('group_id',$id); 
$query=$this->db->delete('njobn_group');
if($query)
{
return 1;
}
else
{
return 0;
}
}
}
function del_ter($id)
{
$this->db->where('consumer_type',$id);
$query=$this->db->delete('manage_terif');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="read_slab";';
echo '</script>';
}
}	
//insert groups
public function insert_groups_record($var)
{
$query=$this->db->insert('njobn_group',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
public function get_where($table,$where=NULL)
{
if($where != NULL){
$this->db->where($where);
}
$query = $this->db->get($table);
if($query->num_rows > 0){
return $query->result();
}
}
//read record for assign_privalges
public function read_assgine_privileges_record()
{

$query=$this->db->get('njobn_assigne_privilege_group');
return $query->result();

}	
//
function chk_permission($where)
{
$this->db->select('pre.file_name');
$this->db->from('njobn_users ad');
$this->db->join('njobn_group gr','gr.group_id=ad.group_id','inner');
$this->db->join('njobn_assigne_privilege_group apg','gr.group_id=apg.group_id','inner');
$this->db->join('njobn_privileges pre','apg.privilege_id = pre.privilege_id','inner');
$this->db->where($where);
$query = $this->db->get();
$return_permission = array();
if($query->num_rows > 0){			
$return = $query->result();
foreach($return as $row)
{
$return_permission[$row->file_name] = $row->file_name;
}
}
return $return_permission;
}
//delete privalges
function del_rec1($table,$where)
{
$query = $this->db->delete($table,$where);
if($query){
return true;
}else{
return false;
}
}



//add privalges
function insert_data($table,$data)
{
$query = $this->db->insert($table,$data);
if($query){
return true;
}else{
return false;
}
}

function join_two_result($table1,$table2,$relation,$group=NULL,$where=NULL)
{
$this->db->select('*');
$this->db->from($table1);
$this->db->join($table2,$relation,'inner');
if($group != NULL){
$this->db->group_by($group);
}
if($where != NULL){
$this->db->where($where);
}
$query = $this->db->get();
if($query->num_rows > 0){

return $query->result();

}
}				

function get_supplier_name($q){
$this->db->select('name');
$this->db->like('name', $q);
$query = $this->db->get('supplier');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['name'])); //build an array
}
echo json_encode($row_set); //format the array into json data
}
}	

//insert payment record
public function insert_payment_record($ref,$date)
{


/*$select=array('reference_num'=>$ref,'bill_month'=>$bill_month);
$query1=$this->db->get('bill_record');
$varaible=$query1->result();
if($query1->num_rows==0)
{
echo "<script>alert('Reference Number And Date is not exist');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="read_reading_record";';
echo '</script>'; 	
}
else
{*/


$select=array('reference_num'=>$ref);
$value=array('paid_status'=>1,'bill_payment_date'=>$date);
$this->db->where($select);
$this->db->order_by('bill_month DESC Limit 1');
$this->db->update('bill_record',$value);
					
echo '<script type="text/javascript">' . "\n";
echo 'window.location="read_reading_record";';
echo '</script>'; 													   	

}
//import refernce number

//read incorrect refernce 
public function incorrect_reference()
{	
$query=$this->db->get('print_ref_table');
return $query->result();	
}						
public function print_reference()
{	
$query=$this->db->get('print_ref_table');
return $query->result();	
}
//code from muktar
public function get_tarrif_record($ref_no)
{		
$this->db->where('consumer_type',$ref_no);
$this->db->order_by('slab_start');
$this->db->order_by('consumer_type');
$query=$this->db->get('manage_terif');

if($query)
{
return $query->result_array();
}



}


public function get_reference($ref_no,$table)
{		


$this->db->where('reference_num',$ref_no);
$query=$this->db->get($table);
if($query->num_rows()==1)
{	
return $query->result();

}
else
{
return false;
}



}




public function get_reference_multi($table)
{		
$this->db->join("consumer","con_meter_map.consumer_id =consumer.consumer_id","inner");
$query=$this->db->get($table);
return $query->result();		
}
public function get_reference_multi_consumer($table,$con_type)
{		
$this->db->where('consumer_type',$con_type);

$query=$this->db->get($table);
if($query->num_rows()>0)
{	
return $query->result();

}
else
{
echo "<script>alert('There is no record of this consumer type');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="generate_bills";';
echo '</script>'; 
}

}

public function get_other_charges($consumer,$table)
{	
$query=$this->db->get($table);
$a=$query->result();
if($a!="")
{
foreach($a as $b)
{
if($consumer=="Domestic")
{
return $b->domestic;
}
if($consumer=="Comercial")
{
return $b->comercial;
}
if($consumer=="Industrial")
{
return $b->industrial;
}
}

}
else
{
echo " No record added for Other charges"." ".$consumer;
}


}

public function get_late_panelty($consumer,$table)
{	
$query=$this->db->get($table);
$a=$query->result();


if($a!="")
{
foreach($a as $b)
{
if($consumer=="Domestic")
{
return $b->domestic;
}
if($consumer=="Comercial")
{
return $b->comercial;
}
if($consumer=="Industrial")
{
return $b->industrial;
}
}

}
else
{
echo " No record added for late pananelty"." ".$consumer;
}



}


public function get_reading($meter_num,$table,$month,$year)
{




$this->db->where('meter_num',$meter_num);
$data=$this->db->get($table);


if($data->num_rows()!=="")
{	
$this->db->where('meter_num',$meter_num);
$this->db->group_by('MONTH(reading_date), YEAR(reading_date)');
$this->db->order_by('reading_date', 'DESC');
$this->db->select('reading');
$this->db->select('reading_date');
$rows=$this->db->get('meter_reading',2);

if($rows->num_rows()>1)
{	
$row=$rows->result_array();
$current=$row[0]['reading'];
$reading_date=$row[0]['reading_date'];
$pre_reading=$row[1]['reading'];

$c=array('reading'=>$current,
'ini_reading'=>$pre_reading,
'reading_date'=>$reading_date
	);
return $c;


}

if($rows->num_rows()==1)
{
$this->db->where('meter_num',$meter_num);
$this->db->select('intial_meter_reading');
$initial=$this->db->get('meter_record');

if($initial->num_rows()==1)
{	$row=$rows->result_array();
foreach($row as $a)
{
$current=$a['reading'];
$reading_date=$a['reading_date'];
}
$init=$initial->result_array();
foreach($init as $ini)
{
$ini_reaing=$ini['intial_meter_reading'];
}

$c=array('reading'=>$current,
'ini_reading'=>$ini_reaing,
'reading_date'=>$reading_date
	);
return $c;


}
}
}
else
{
echo "There is no record of reading";
}

}
public function read_installment($ref_num,$table)
{
$this->db->where('reference_num',$ref_num);
$query=$this->db->get($table);
$a=$query->result();
foreach($a as $record)
{
$amount=$record->amount;
$noofinstallment=$record->num_of_install;
$remaining=$record->remaining_amount;
$status=$record->status;
$paid=$record->paid_installment;

}

if($query->num_rows()==1)
{	
if($amount==0)
{
$installment_amount=1;
}
else
{

$installment_amount=floor($amount/$noofinstallment);
}
$return=array('amount'=>$amount,'remaining_amount'=>$remaining,
'paid_amount'=>$paid,'installment'=>$installment_amount,'status'=>$status);
return $return;
}
else
{
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>0);
return $return;
}
}

public function get_installment($ref_num,$table)

{ 
$this->db->where('reference_num',$ref_num);
$query=$this->db->get($table);
if($query->num_rows()==1)
{
$a=$query->result();

foreach($a as $record)
{
$amount=$record->amount;
$noofinstallment=$record->num_of_install;
$remaining=$record->remaining_amount;
$status=$record->status;
$paid=$record->paid_installment;
}


if($paid==0 && $status==1)
{
$installment_amount=floor($amount/$noofinstallment);
$remainder=fmod($amount,$noofinstallment);
$remaining_amount=$amount-$installment_amount-$remainder;
$paid_amount=$installment_amount+$remainder;
$value=array('remaining_amount'=>$remaining_amount,'paid_installment'=>$paid_amount);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
if($update)
{
$return=array('amount'=>$amount,'remaining_amount'=>$remaining,
'paid_amount'=>$paid,'installment'=>$installment_amount,'status'=>$status);

return $return;
}
}

if($paid!=$amount && $status==1)
{$installment_amount=floor($amount/$noofinstallment);
$remaining_amount=$remaining-$installment_amount;
$paid_amount=$paid+$installment_amount;
$value=array('remaining_amount'=>$remaining_amount,'paid_installment'=>$paid_amount);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
if($update)
{
$return=array('amount'=>$amount,'remaining_amount'=>$remaining,
'paid_amount'=>$paid,'installment'=>$installment_amount,'status'=>$status);

return $return;
}
}
if($amount==$paid &&  $status==1)
{
$value=array('status'=>0,'num_of_install'=>1,'remaining_amount'=>0);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>$status);
if($update)
{			
return $return;
}
}

if($status==0 )
{
$value=array('status'=>0,'amount'=>0,'paid_installment'=>0,'num_of_install'=>1,'remaining_amount'=>0);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>$status);
if($update)
{			
return $return;
}
}


else
{
return false;
}



}
}
public function insert_bill_record($recored,$table,$month,$year,$ref_num)
{
//code for validation	
$this->db->where('EXTRACT(MONTH FROM bill_month)= ',$month);
$this->db->where('EXTRACT(YEAR FROM bill_month)= ',$year);
$this->db->where('reference_num',$ref_num);
$this->db->where('paid_status',1);
$query1=$this->db->get($table);
if($query1->num_rows>0)
{
return false; 	
}	
else
{
$this->db->where('EXTRACT(MONTH FROM bill_month)= ',$month);
$this->db->where('EXTRACT(YEAR FROM bill_month)= ',$year);
$this->db->where('paid_status',0);
$this->db->where('reference_num',$ref_num);
$query2=$this->db->get($table);
if($query2->num_rows==0)
{	
$query=$this->db->insert($table,$recored);
return true;
}   
else
{
$this->db->where('EXTRACT(MONTH FROM bill_month)= ',$month);
$this->db->where('EXTRACT(YEAR FROM bill_month)= ',$year);
$this->db->where('paid_status',0);
$this->db->where('reference_num',$ref_num);
$query=$this->db->update($table,$recored);
return true;
}
}






}



public function get_con_record($pass,$table)
{
$this->db->where($pass);
$query=$this->db->get($table);
if($query->num_rows()==1)
{
$record=$query->result();	
foreach($record as $a)
{
$name=$a->first_name;
$last_name=$a->last_name;
$contact=$a->contact;
$status=$a->status;
$cnic=$a->cnic;
$address=$a->address;
$consumer=array($name,$last_name,$contact,$status,$address,$cnic);
return $consumer;
}
}

}

public function get_bill_print($ref_num,$table,$month,$year,$bill_month)
{
$this->db->where('reference_num',$ref_num);
$rows=$this->db->get($table);

if($rows->num_rows!=0)
{
$this->db->where('reference_num',$ref_num);
$this->db->where('bill_month', $bill_month);

$query=$this->db->get($table);
//var_dump($query->result());break;
return $query->result();

}
else
{
echo "you have no record to view bill";
}

}
public function get_bill_date($ref_num,$table,$month,$year,$bill_month)
{

$this->db->where('reference_num',$ref_num);
$rows=$this->db->get($table);
//var_dump($row->result());break;

if($rows->num_rows!=0)
{
$this->db->where('reference_num',$ref_num);
$this->db->where('bill_month <=',$bill_month);
$this->db->order_by('bill_month', 'DESC');
$query=$this->db->get($table,6,1);


return $query->result();

}


}

public function insert_installment_record($installment,$table,$reference_num)
{
$this->db->where('reference_num',$reference_num);
$this->db->select('status');
$query=$this->db->get($table);
if($query->num_rows()>0)
{
$a=$query->result();
foreach($a as $b)
{
if($b->status==0)
{
$insert=$this->db->update($table,$installment);
return true;
}
else
{
return false;
}
}
}
if($query->num_rows()==0)
{ 
$insert=$this->db->insert($table,$installment);
return true;
}					
}

public function read_bill_installment($ref_num,$table)
{
$this->db->where('reference_num',$ref_num);
$query=$this->db->get($table);
$a=$query->result();
foreach($a as $record)
{
$amount=$record->total_amount;
$noofinstallment=$record->num_of_install;
$remaining=$record->remaining_amount;
$status=$record->status;
$paid=$record->paid_amount;
}
if($query->num_rows()==1)
{
$installment_amount=floor($amount/$noofinstallment);

$return=array('amount'=>$amount,'remaining_amount'=>$remaining,
'paid_amount'=>$paid,'installment'=>$installment_amount,'status'=>$status);
return $return;
}
else
{
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>0);
return $return;
}
}
public function get_bill_installment($ref_num,$table) // ON PAYMENT OF BILL
{ 
$this->db->where('reference_num',$ref_num);
$query=$this->db->get($table);
if($query->num_rows()==1)
{
$a=$query->result();

foreach($a as $record)
{
$amount=$record->total_amount;
$noofinstallment=$record->num_of_install;
$remaining=$record->remaining_amount;
$status=$record->status;
$paid=$record->paid_amount;
}


if($paid==0 && $status==1)
{

$installment_amount=floor($amount/$noofinstallment);
$remainder=fmod($amount,$noofinstallment);
$remaining_amount=$amount-$installment_amount-$remainder;
$paid_amount=$installment_amount+$remainder;
$value=array('remaining_amount'=>$remaining_amount,'paid_amount'=>$paid_amount);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);

if($update)
{
$return=array('amount'=>$amount,'remaining_amount'=>$remaining,
'paid_amount'=>$paid,'installment'=>$installment_amount,'status'=>$status);
return $return;	
}
}

if($paid!=$amount && $status==1)
{$installment_amount=floor($amount/$noofinstallment);
$remaining_amount=$remaining-$installment_amount;
$paid_amount=$paid+$installment_amount;
$value=array('remaining_amount'=>$remaining_amount,'paid_amount'=>$paid_amount);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
}
if($amount=$paid &&  $status==1)
{
$value=array('status'=>0,'num_of_install'=>1,'remaining_amount'=>0);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>$status);
if($update)
{			
return $return;
}
}

if($status==0 )
{
$value=array('status'=>0,'total_amount'=>0,'paid_amount'=>0,'num_of_install'=>1,'remaining_amount'=>0);
$this->db->where('reference_num',$ref_num);
$update=$this->db->update($table, $value);
$return=array('amount'=>0,'remaining_amount'=>0,'paid_amount'=>0,'installment'=>0,'status'=>$status);
if($update)
{			
return $return;
}
}


else
{
return false;
}



}
}

public function get_arrears($ref_num,$table,$month,$year,$bill_month)
{
$this->db->where('reference_num',$ref_num);
$rows=$this->db->get($table);
if($rows->num_rows()==0)
{
return 0;
}
else
{
if($rows->num_rows!=0)
{

$this->db->where('reference_num',$ref_num);
$this->db->where('bill_month <',$bill_month);
$this->db->order_by('bill_month','DESC');
$this->db->select('late_bill');
$this->db->select('paid_status');
$query=$this->db->get($table,1);

if($query->num_rows==1)
{	
foreach($query->result() as $record)
{
if($record->paid_status==0)
{	
return $record->late_bill;
}
else
{
return 0;
}
}
}
else
{
return 0;
}
}
else
{
return 0;
}
}


}
public function get_generated_bill()
{
$array=array('status'=>1);
$this->db->where($array);
$query=$this->db->get('bill_installment');

if($query)
{
return $query->result();    
}
else
{ 
return false;
}


}	
//generte bills
public function get_printed($bill_id,$table)
{
$this->db->where('a_id',$bill_id);	
$query=$this->db->get($table);
if($query->num_rows()==1)
{
$value=array('status'=>1);
$this->db->where('a_id',$bill_id);	
$update=$this->db->update($table,$value);
}
}
public function read_out_standing_bills()
{
//join query
$today=date("Y/m/d");
$this->db->where('due_date <',$today);
$this->db->order_by('reference_num DESC');
$this->db->order_by('bill_month DESC');
$query=$this->db->get('bill_record');
return $query->result();	
}
public function read_out_standing_bills1()
{
//join query

$this->db->distinct();
$this->db->select('reference_num');
$query2=$this->db->get('bill_record');
$today=date("Y/m/d");
$a=$query2->result();
foreach($a as $record)
{	$ref=$record->reference_num;
$this->db->where('reference_num',$ref);
$this->db->where('due_date <',$today);
$this->db->select('paid_status');
$this->db->order_by('bill_month DESC');
$query1=$this->db->get('bill_record',3);

if($query1->num_rows()==3)
{
$val=$query1->result();
foreach($val as $b)
{
$count=0;
while($b->paid_status==0)
{
$count++;
if($count==3)
{
$this->db->where('reference_num',$ref);
$this->db->select('paid_status');
$query4=$this->db->get('bill_record',1);
var_dump($query4->result());
}
}
}
}



//break;
}



return $query1->result();	
}
public function read_bills()
{    
$query=$this->db->get('bill_record');
return $query->result();	
}
public function read_bills1()
{
//join query
$this->db->order_by('reference_num DESC');
$this->db->order_by('bill_month DESC');
$query=$this->db->get('bill_record');
return $query->result();	
}
//code for lates bill print
public function latest_bill_print($bill_id)
{
$this->db->where('a_id',$bill_id);	
$query=$this->db->get('bill_record');
return $query->result();	
}
//code for mothly bills
public function generte_monthly_bills($month,$year)
{

}
//read print biils
public function read_print_bills()
{ 
/*$this->db->where('status','1'); */  
$query=$this->db->get('bill_record');
return $query->result();	
}
//code for sinngle bill

public function get_bill_date_print($ref_num,$table,$month,$year,$bill_month)
{
$this->db->where('reference_num',$ref_num);
$rows=$this->db->get($table);
//var_dump($row->result());break;

if($rows->num_rows!=0)
{
$this->db->where('reference_num',$ref_num);
$this->db->where('bill_month <=',$bill_month);
$this->db->order_by('bill_month', 'DESC');
$query=$this->db->get($table,6,1);


return $query->result();

}
else
{
echo "<script>alert('Enter Right Reference Number');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="issue_print_bill";';
echo '</script>';
exit;
}

}
public function get_bill_print_print($ref_num,$table)
{
$this->db->where('reference_num',$ref_num);
$rows=$this->db->get($table);

if($rows->num_rows!=0)
{
$this->db->where('reference_num',$ref_num);
$this->db->group_by('MONTH(issue_date), YEAR(issue_date)');
$this->db->order_by('issue_date', 'DESC');
$query=$this->db->get($table,1);
//var_dump($query->result());break;
return $query->result();

}
else
{
echo "<script>alert('Enter Right Reference Number');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="issue_print_bill";';
echo '</script>';
exit;
}

}	
public function get_printed_status($bill_id,$table)
{	
$this->db->where('a_id',$bill_id);	
$query=$this->db->get($table);
if($query->num_rows()==1)
{
$value=array('status'=>1);
$this->db->where('a_id',$bill_id);	
$update=$this->db->update($table,$value);
}
}	
//generete multiple prints
public function get_reference_multi_print($table)
{		
$this->db->join("consumer","con_meter_map.consumer_id =consumer.consumer_id","inner");
$query=$this->db->get($table);
if($query->num_rows()>0)
{
return $query->result();	
}
else
{
echo "<script>alert('There is no record of this consumer type');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="issue_print_bill";';
echo '</script>';
exit;
}
}
public function get_consumer_print($table,$con_type)
{		

$this->db->where('consumer_type',$con_type);
$query=$this->db->get($table);
if($query->num_rows()>0)
{
return $query->result();	
}
else
{
echo "<script>alert('There is no record of this consumer type');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="issue_print_bill";';
echo '</script>';
exit;
}	
}			
//read reason for edit page
public function add_reason($id)
{	
$this->db->where('a_id',$id);
$query=$this->db->get('con_meter_map');
return $query->result();
}	
public function enter_reason($rsults)
{
$insert=$this->db->insert('add_reason',$rsults);
if($insert)
{
return true;
}
else
{
false;	
}
}
//dlete code for incorrect enteries
function delete_meter_reading_print($table,$id)
{
$this->db->where('a_id',$id);
$query = $this->db->delete($table);
if($query){
return true;
}else{
return false;
}
}

//delete code print refence number
function delete_print_refernce($table,$id)
{
$this->db->where('id',$id);
$query = $this->db->delete($table);
if($query){
return true;
}else{
return false;
}
}
//delete code jobs category
function delete_jobs_category($table,$id)
{
//first check already exixt recorde in jobs destils page
$this->db->where('industeries_id',$id);
$query1 = $this->db->get('njobn_industeries');
if($query1->num_rows() ==0)
{ 
$this->db->where('jobs_category_id',$id);
$query = $this->db->delete($table);
if($query)
{
return true;
}
else
{
return false;
}
}
}
//delete code jobs 
function delete_job($table,$id)
{
$this->db->where('job_id',$id);
$query = $this->db->delete($table);
if($query){
return true;
}else{
return false;
}
}
//generte monthly bills record	
//generte monthly bills record	
public function add_report_consumer($fromdate,$todate,$consumer_type)
{
//ineer jion query	
/*$this->db->join("consumer","con_meter_map.consumer_id =consumer.consumer_id","inner");*/

if($consumer_type=="All")
{
$this->db->where('created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("consumer");
}
else
{
$this->db->where('created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$this->db->where('consumer_type',$consumer_type);
$query = $this->db->get("consumer");
}
if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_consumer_witout_date($fromdate,$todate,$consumer_type)
{
//ineer jion query
if($consumer_type=="All")
{
//$this->db->join("consumer","con_meter_map.consumer_id =consumer.consumer_id","inner");
$query = $this->db->get("consumer");
}
else
{
/*$this->db->join("consumer","con_meter_map.consumer_id =consumer.consumer_id","inner");*/
$this->db->where('consumer_type',$consumer_type);
$query = $this->db->get("consumer");
}
if($query){
return $query->result();
}else{
return false;
}
}
//code installment report
public function add_report_install($fromdate,$todate,$consumer_type)
{
//ineer jion query	
if($consumer_type=="All")
{
$this->db->join("bill_installment","con_meter_map.reference_num =.reference_num","inner");
$this->db->where('bill_installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("con_meter_map");	
}
else
{
$this->db->join("bill_installment","con_meter_map.reference_num =.reference_num","inner");
$this->db->where('bill_installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$this->db->where('bill_installment.consumer_type',$consumer_type);
$query = $this->db->get("con_meter_map");	
}

if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_install_witout_date($fromdate,$todate,$consumer_type)
{
//ineer jion query
if($consumer_type=="All")
{
$this->db->join("bill_installment","con_meter_map.reference_num =bill_installment.reference_num","inner");
$query = $this->db->get("con_meter_map");
}
else
{
$this->db->join("bill_installment","con_meter_map.reference_num =bill_installment.reference_num","inner");
$this->db->where('bill_installment.consumer_type',$consumer_type);
$query = $this->db->get("con_meter_map");
}
if($query){
return $query->result();
}else{
return false;
}
}
//code for connection charges
public function add_report_charge($fromdate,$todate,$consumer_type)
{
//ineer jion query	

if($consumer_type=="All")
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("con_meter_map");	
}
else
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$this->db->where('installment.consumer_type',$consumer_type);
$query = $this->db->get("con_meter_map");
}
if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_charge_witout_date($fromdate,$todate,$consumer_type)
{
//ineer jion query
if($consumer_type=="All")
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$query = $this->db->get("con_meter_map");
}
else
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.consumer_type',$consumer_type);
$query = $this->db->get("con_meter_map");
}
if($query){
return $query->result();
}else{
return false;
}
}
//code for meter report
public function add_report_meter($fromdate,$todate,$meter_status)
{
//ineer jion query	
if($meter_status=="All")
{
$this->db->where('created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("meter_record");	
}
else
{
$this->db->where('meter_status',$meter_status);	
$this->db->where('created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("meter_record");
}
if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_meter_witout_date($fromdate,$todate,$meter_status)
{
//ineer jion query
if($meter_status=="All")
{		
$query=$this->db->get("meter_record");
}
elseif($meter_status==1)
{

$this->db->where('status',1);	
$query = $this->db->get("meter_record");
}
elseif($meter_status!=0 || $meter_status!=1)
{
$this->db->where('meter_status',$meter_status);
$query = $this->db->get("meter_record");	
}
elseif($meter_status==0)
{
$this->db->where('status',0);	
$query = $this->db->get("meter_record");
}
else
{	
$this->db->where('meter_status',$meter_status);
$query = $this->db->get("meter_record");
}
if($query){
return $query->result();
}else{
return false;
}
}

//code for generte reports
public function list_all_meter($table,$regions)
{
if($regions=='')
{
$query=$this->db->get($table);
return $query->result(); 	
}
else
{
$this->db->where('region_id',$regions);	
$query=$this->db->get($table);
return $query->result(); 
}
}

public function list_status_meter($check,$table)
{
$this->db->where($check);
$query=$this->db->get($table);
return $query->result(); 

}
public function list_status_consumer($check,$table)
{

$this->db->where($check);
$query=$this->db->get($table);
return $query->result(); 
}
//code for regions
//code for to read privaliges
public function read_regions_record()
{

$query=$this->db->get('regions');
return $query->result();

}	
//code for revenue
public function read_revenue_record()
{
/*$this->db->select('regions.Name,regions.Region_id ,SUM(bill_record.total_bill) as total_billsum,SUM(bill_record.late_bill) as late_billsum');	
$this->db->join("bill_record","regions.Region_id =bill_record.region_id","inner");*/
$query = $this->db->get("regions");
if($query->num_rows()>0)
{
return $query->result();
}
}
public function read_revenue_record1($bill_month)
{
/*$this->db->select('regions.Name,regions.Region_id , SUM(bill_record.total_bill) as total_billsum,SUM(bill_record.late_bill) as late_billsum');			
$this->db->join("bill_record","regions.Region_id =bill_record.region_id","inner");
$this->db->where('bill_month', $bill_month);*/

$query = $this->db->get("regions");
if($query->num_rows()>0)
{
return $query->result();
}
}

//code for to delete user
function del_regions($id)
{
$this->db->where('Region_id',$id);
$query=$this->db->delete('regions');
if($query){
return true;
}
}
//insert privillges
public function insert_regions_record($var,$id)
{
$this->db->where('Region_id',$id);
$query=$this->db->get('regions');
if($query->num_rows()>0)
{
echo "<script>alert('Region Id Already Exist');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="regions";';
echo '</script>';	 
}
else
{
$query=$this->db->insert('regions',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
}
public function get_customer_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("customer");
if($query){
return $query->result();
}else{
return false;
}
}
//suppler report code
public function get_supplier_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("supplier");
if($query){
return $query->result();
}else{
return false;
}
}
//product report code
public function get_product_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("product");

if($query){
return $query->result();
}else{
return false;
}
}
 // get location name
    function get_location_name($q){
    $this->db->select('name');
    $this->db->like('name', $q);
    $query = $this->db->get('countries');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['name'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
  // get job title
    function get_job_title($q){
	$this->db->distinct();
    $this->db->select('job_title');
    $this->db->like('job_title', $q);
    $query = $this->db->get('njobn_jobdetails');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['job_title'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
  
  function get_job_titlerec($q,$user_id){
  $this->db->distinct();
    $this->db->select('job_title');
    $this->db->like('job_title', $q);
	$this->db->where('created_by',$user_id);
    $query = $this->db->get('njobn_jobdetails');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['job_title'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
  // code for to get city
      function get_city_state1($q){
    $this->db->select('name');
    $this->db->like('name', $q);
    $query = $this->db->get('cities');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['name'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
      function get_job_title1($q){
	  $this->db->distinct();
    $this->db->select('job_title');
    $this->db->like('job_title', $q);
    $query = $this->db->get('njobn_jobdetails');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['job_title'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
  //get job skills
   function get_job_skills($q){
    $this->db->select('skill_name');
    $this->db->like('skill_name', $q);
    $query = $this->db->get('skills');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['skill_name'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
  
//expenses report code
public function get_expenses_report($fromdate,$todate)
{
$this->db->where('exp_date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("expenses");

if($query){
return $query->result();
}else{
return false;
}
}
//sale report code
public function get_sale_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("sales");
if($query){
return $query->result();
}else{
return false;
}
}
//receving report code
public function get_received_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("recieves");
if($query){
return $query->result();
}else{
return false;
}
}
//purchase report code
public function get_purchase_report($fromdate,$todate)
{
$this->db->where('date BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$query = $this->db->get("purchase");
if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_installment_region($fromdate,$todate,$regions,$consumer_type,$select_date)
{
//ineer jion query	
if($select_date=="date")
{	
$this->db->join("bill_installment","con_meter_map.reference_num =bill_installment.reference_num","inner");
$this->db->where('bill_installment.consumer_type',$consumer_type);
$this->db->where('bill_installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');	
$this->db->where('bill_installment.region_id',$regions);
$query = $this->db->get("con_meter_map");
}
elseif($consumer_type=="All" && $regions!='')
{
$this->db->join("bill_installment","con_meter_map.reference_num =bill_installment.reference_num","inner");
$this->db->where('bill_installment.region_id',$regions);
$query = $this->db->get("con_meter_map");	
}
else
{
$this->db->join("bill_installment","con_meter_map.reference_num =bill_installment.reference_num","inner");
$this->db->where('bill_installment.consumer_type',$consumer_type);
$this->db->where('bill_installment.region_id',$regions);
$query = $this->db->get("con_meter_map");
}

if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_connection_region($fromdate,$todate,$regions,$consumer_type,$select_date)
{
//ineer jion query	
if($select_date=="date")
{	
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.consumer_type',$consumer_type);
$this->db->where('installment.created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');
$this->db->where('installment.region_id',$regions);
$query = $this->db->get("con_meter_map");
}
elseif($consumer_type=="All" && $regions!='')
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.region_id',$regions);
$query = $this->db->get("con_meter_map");	
}
else
{
$this->db->join("installment","con_meter_map.reference_num =installment.reference_num","inner");
$this->db->where('installment.consumer_type',$consumer_type);
$this->db->where('installment.region_id',$regions);
$query = $this->db->get("con_meter_map");
}
if($query){
return $query->result();
}else{
return false;
}
}
public function add_report_meter_region($fromdate,$todate,$regions,$meter_status,$select_date)
{
//ineer jion query	
if($select_date=="date")
{

$this->db->where('created_on BETWEEN "'.$fromdate. '" and "'.$todate.'"');
$this->db->where('meter_status',$meter_status);	
$this->db->where('region_id',$regions);
$query = $this->db->get("meter_record");
}
elseif($meter_status=="All" && $regions!='')
{

$this->db->where('region_id',$regions);	
$query = $this->db->get("meter_record");	
}
else
{

$this->db->where('meter_status',$meter_status);	
$this->db->where('region_id',$regions);	
$query = $this->db->get("meter_record");
}
if($query){
return $query->result();
}else{
return false;
}
}
public function all_deficit_report()
{
//ineer jion query
$this->db->where('amount >',0);
$query=$this->db->get('shorts_payment');
if($query->num_rows>0)
{
return $query->result();
}
else
{
echo "<script>alert('There is no record of deficit amount');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="deficit_amount_report";';
echo '</script>';
exit;	
}

}

public function monthly_deficit_report($date)
{
$this->db->where('amount >',0);
$this->db->where('bill_month',$date);
$query=$this->db->get('shorts_payment');
if($query->num_rows>0)
{
return $query->result();
}
else
{
echo "<script>alert('There is no record of deficit amount');</script>";	 			  							
echo '<script type="text/javascript">' . "\n";
echo 'window.location="deficit_amount_report";';
echo '</script>';
exit;	
}

}
//cod for read tarrif history
public function terrif_history($table,$region)
{
/*$this->db->group_by("title");*/
$this->db->where('region_id',$region);
$query=$this->db->get($table);
return $query->result();

}
//cod for read panelty  history
public function late_panelty_history($table,$region)
{
/*$this->db->group_by("title");*/
$this->db->where('region_id',$region);
$query=$this->db->get($table);
return $query->result();

}
//cod for read other_charges_history  
public function other_charges_history($table,$region)
{
/*$this->db->group_by("title");*/
$this->db->where('region_id',$region);
$query=$this->db->get($table);
return $query->result();

}
//inssert sale recorde
public function insert_sale_record($var)
{
$query=$this->db->insert('sales',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//inssert purchase recorde
public function insert_purchase_record($var)
{
$query=$this->db->insert('purchase',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//cod for read update_texes_history  
public function update_texes_history($table,$region)
{
/*$this->db->group_by("title");*/
$this->db->where('region_id',$region);
$query=$this->db->get($table);
return $query->result();

}
//add job details 
public function insert_job_add_record($var)
{
$query=$this->db->insert('njobn_jobdetails',$var);
$job_id = $this->db->insert_id();
//error_reporting(0);
error_reporting(0);
foreach ($_POST['secters'] as $selectedOption)
{
if($selectedOption!=0)
{
$sql_insert=mysql_query("insert into njobn_industeries set job_id='".$job_id."',
						 date='".date("Y/m/d")."', 
						  industeries_id='".$selectedOption."'");
}
}

if($query)
{
return true;
}
else
{
return false;
}
}
//code for view jobs
public function read_viewjob_record()
{
$query=$this->db->get('njobn_jobdetails');
return $query->result();	
}	
//codef for to show jobs listed by candiate in report
public function read_viewjob_recordrep($can_id)
{
$this->db->where('created_by',$can_id);
$query=$this->db->get('njobn_jobdetails');
return $query->result();	
}
//code for to show users of recuters
public function get_users_cv_down($can_id)
{
$this->db->where('created_by',$can_id);
$query=$this->db->get('njobn_webusers');
if($query->num_rows() >0)
{
return $query->result();	
}
else
{
return false;	
}	
}
//code to show the userscvdownloads
public function get_cvdowloads($can_id)
{
$this->db->where('view_by',$can_id);
$query=$this->db->get('cv_counters');
return $query->result();		
}
//code for to show data on edit_job page
public function read_jobedit_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_jobdetails');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to update form
public function update_jobs_record($id,$var)
{	
$this->db->where('job_id', $id);
$query=$this->db->update('njobn_jobdetails', $var);
error_reporting(0);
foreach ($_POST['secters'] as $selectedOption)
{
$sel_count_number_rows=mysql_query("select * from njobn_industeries where job_id='".$id."' AND  industeries_id='".$selectedOption."'");
$number_delete_rows=mysql_num_rows($sel_count_number_rows);
if($number_delete_rows >0)
{
//delete query before insert
$delete=mysql_query("delete from njobn_industeries where job_id='".$id."'");
}
if($selectedOption!=0)
{
$sql_insert=mysql_query("insert into njobn_industeries set job_id='".$id."',
						 date='".date("Y/m/d")."', 
						  industeries_id='".$selectedOption."'");
}
}
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show dat on viewjob
public function read_viewjobsdeatilss_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_jobdetails');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	

public function read_viewjobsdeatilss_record1($pass)
{
$this->db->where('created_by', $pass);
$query=$this->db->get('njobn_jobdetails');
return $query->result();	
}
//add webuer code
public function insert_webuser_record($var)
{
$query=$this->db->insert('njobn_webusers',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show web users grid
public function read_webuser_record($var)
{
	$this->db->where('user_type', $var);
$query=$this->db->get('njobn_webusers');
return $query->result();
}
//code for to delete web users
function del_webrecuser($id)
{
$this->db->where('user_id',$id);
$query=$this->db->delete('njobn_webusers');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="webuser";';
echo '</script>';
}
}
//code for show eidt web user
public function read_webedit_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('njobn_webusers');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to edit data of user user section
public function update_webuser_record($id,$var)
{	
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to webview users
public function read_webuser1_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_webusers');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to delete team memeber
function del_team($id)
{
$this->db->where('team_id',$id);
$query=$this->db->delete('njobn_teamold');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="team";';
echo '</script>';
}
}
//code for to show team memebr grid
public function read_team_record()
{
$query=$this->db->get('njobn_teamold');
return $query->result();
}
//code for to add team lead
public function insert_team_record($var)
{
$query=$this->db->insert('njobn_teamold',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update team
public function update_teammemebr_record($id,$var)
{	
$this->db->where('team_id', $id);
$query=$this->db->update('njobn_teamold', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show data of viewteam section
public function read_teammember_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_teamold');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show data for edit team memebr
public function read_teameditpage_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_teamold');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}	
//code for to show testimonials memebr grid
public function read_testimonials_record()
{
$query=$this->db->get('njobn_testimonials');
return $query->result();
}
//code for to delete team memeber
function del_testimonials($id)
{
$this->db->where('testimonials_id',$id);
$query=$this->db->delete('njobn_testimonials');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="testimonials";';
echo '</script>';
}
}
//code for to add testimonials lead
public function insert_testimonials_record($var)
{
$query=$this->db->insert('njobn_testimonials',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update team
public function update_testimonials_record($id,$var)
{	
$this->db->where('testimonials_id', $id);
$query=$this->db->update('njobn_testimonials', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show data for edit 
public function read_testimonialsedipage_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('edit_testimonials');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show data of viewteam section
public function read_viewtestimonials_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('njobn_testimonials');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show skilss grid
public function read_skills_record()
{
$query=$this->db->get('skills');
return $query->result();
}
//code for to delete team memeber
function del_skills($id)
{
$this->db->where('skill_id',$id);
$query=$this->db->delete('skills');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="skills";';
echo '</script>';
}
}
// add skill form
public function insert_skills_record($var)
{
$query=$this->db->insert('skills',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update team
public function update_skills_record($id,$var)
{	
$this->db->where('skill_id', $id);
$query=$this->db->update('skills', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show data of viewteam section
public function read_viewskills_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('skills');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show languages grid
public function read_languages_record()
{
$query=$this->db->get('languages');
return $query->result();
}
//code for to delete languages
function delete_languages($id)
{
$this->db->where('language_id',$id);
$query=$this->db->delete('languages');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="languages";';
echo '</script>';
}
}
// add skill 
public function insert_languages_record($var)
{
$query=$this->db->insert('languages',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update languages
public function update_languages_record($id,$var)
{	
$this->db->where('language_id', $id);
$query=$this->db->update('languages', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show data of view languages
public function read_languagesview_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('languages');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//show data for eidt Labguages
public function read_editlanguages_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('languages');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to cms pages grid
public function read_cmspages_record()
{
$query=$this->db->get('pages');
return $query->result();
}
//show data for eidt cms page
public function read_editcmspage_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('pages');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to update cms page data
public function update_cms_record($id,$var)
{	
$this->db->where('id', $id);
$query=$this->db->update('pages', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to add cms page
public function add_cms_record($var)
{	
$query=$this->db->insert('pages', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//show data for eidt templtese
public function read_editemailtemplates_record($pass)
{

$this->db->where($pass);
$query=$this->db->get('email_templtes');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to Email Templet pages grid
public function read_email_templates_record()
{
$query=$this->db->get('email_templtes');
return $query->result();
}
//code for to update email templtes
public function update_templtes_record($id,$var)
{	
$this->db->where('id', $id);
$query=$this->db->update('email_templtes', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to Email Templet pages grid
public function read_website_record()
{
$query=$this->db->get('setting');
return $query->result();
}
//code for to update email templtes
public function update_websiteseeting_record($id,$var)
{	
$this->db->where('setting_id', $id);
$query=$this->db->update('setting', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//get profile data
public function read_profile_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('njobn_candidate');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
}	
//get employe profiel data
public function read_profile_recordemp($pass)
{
$this->db->where($pass);
$query=$this->db->get('njobn_employee');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
}	
//code for to adress ,email ,phone
public function read_adress_email($pass)
{
$this->db->where($pass);
$query=$this->db->get('njobn_webusers');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
}	
//code for add locations doe cand
public function insert_can_locations($var)
{
$query=$this->db->insert('candidate_locations',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
public function update_can_locations($id,$var)
{	
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id', $candidate_id);
$this->db->where('location_id', $id);
$query=$this->db->update('candidate_locations', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for show lccations oin candiat dashboard
public function get_can_locations($candidate_id)
{
$this->db->where($candidate_id);
$query=$this->db->get('candidate_locations');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show sectors for candi profile
public function get_can_sectors($candidate_id)
{
$this->db->where($candidate_id);
$query=$this->db->get('candidate_industeries');
return $query->result();	
}
//dlete job location
function delete_job_locatoion($id)
{
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id',$candidate_id);
$this->db->where('location_id',$id);
$query = $this->db->delete("candidate_locations");
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to delete shot list job
function delete_shortlisjob($id)
{
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id',$candidate_id);
$this->db->where('job_id',$id);
$query = $this->db->delete("shot_listjob");
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to delete sector
function delete_sector($id)
{
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id',$candidate_id);
$this->db->where('industeries_id',$id);
$query = $this->db->delete("candidate_industeries");
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show data on edit page
public function read_joblocation_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('countries');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for show secteros on update sector page 
public function read_sector_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('candidate_industeries');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for to show job type on  front end dasboard
public function get_job_typees($candidate_id)
{
$this->db->where($candidate_id);
$query=$this->db->get('job_type');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
}
//update candiat profile data
public function update_can_prfile_data($id,$var)
{	
$this->db->where('candidate_id', $id);
$query=$this->db->update('njobn_candidate', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for update show personal information
public function read_personalinfo($pass)
{
$this->db->where($pass);
$query=$this->db->get('njobn_webusers');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
public function read_work_history_data($candidate_id)
{
$this->db->where('candidate_id',$candidate_id);
$query=$this->db->get('work_history');
return $query->result();
}
//update personal infor 
public function update_personal_record($id,$var)
{	
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//sedn email contact us

public function send_contact_email($name,$email,$category,$subject,$message)
{
//send email code 
$sel_admin=mysql_query("select * from  njobn_users where group_id='9'");
$sel_fetc_adminemail=mysql_fetch_array($sel_admin);
$to =$sel_fetc_adminemail['email'];
$from =$email;
$body = "A user $name submitted the contact form:<br>".
"Name: $name <br>".
"Email: $email <br>".
"Category: $category <br>".
"Message: <br>".
"$message<br>";	
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mail=mail($to, $subject, $body,$headers);	
if($mail)
{	
return true;
}
}
//code for to insert file uploaded
public function insert_file_record($var)
{
$id=$this->session->userdata('user_id');
//code for to add cvcounter
$insert_conter=mysql_query("insert into cv_counters set  candidate_id='".$id."',
										date='".date("Y/m/d")."'");
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//update cover latter info
public function insert_cover_record($var)
{
$id=$this->session->userdata('user_id');
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code fot to add work history
public function insert_workhostrt_record($var)
{
$query=$this->db->insert('work_history', $var);
if($query)
{
return true;
}
else
{
return false;
}
}

//code for to delete work history
function delete_work_history($id)
{
$this->db->where('work_id',$id);
$query = $this->db->delete("work_history");
if($query)
{
return true;
}
else
{
return false;
}
}
//edit code for update work hisory
public function read_workhistory_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('work_history');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//update work history
public function  update_workhistory_record($recorde,$id)
{
$this->db->where('work_id', $id);
$query=$this->db->update('work_history',$recorde);
if($query)
{
return true;
}
else
{
return false;
}
}
//add qulifationcs work
public function add_qualifications_record($var)
{
$query=$this->db->insert('qualifications', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to delete qulifications
function delete_qualifications_recorde($id)
{
$this->db->where('qualifications_id',$id);
$query = $this->db->delete("qualifications");
if($query)
{
return true;
}
else
{
return false;
}
}
//code to show the edit quification page data 
public function read_qualifications_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('qualifications');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code fro to update quilafication form data 
public function  update_qualificationstable_record($recorde,$id)
{
$this->db->where('qualifications_id', $id);
$query=$this->db->update('qualifications',$recorde);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to show the data in grid table
public function qualificatins_grid_data($candidate_id)
{

$this->db->where('candidate_id',$candidate_id);
$query=$this->db->get('qualifications');
return $query->result();
}
//code for to add skilss
public function qualificatins_skills_data($candidate_id)
{
$this->db->where('candidate_id',$candidate_id);
$query=$this->db->get('candidate_skills');
return $query->result();
}
public function qualificatins_license_data($candidate_id)
{
$this->db->where('candidate_id',$candidate_id);
$query=$this->db->get('candidate_license');
return $query->result();
}
function delete_skills($id)
{
$this->db->where('id',$id);
$query = $this->db->delete("candidate_skills");
if($query)
{
return true;
}
else
{
return false;
}
}
// get work language names
    function get_language_name($q){
    $this->db->select('language_name');
    $this->db->like('language_name', $q);
    $query = $this->db->get('languages');
    if($query->num_rows > 0)
	{
      foreach ($query->result_array() as $row){
        $row_set[] = htmlentities(stripslashes($row['language_name'])); //build an array
      }
      echo json_encode($row_set); //format the array into json data
    }
  }
 //code to get the show the lagnuges on cand page
 public function get_can_languages($candidate_id)
{
$this->db->where($candidate_id);
$query=$this->db->get('candidate_language');
if($query)
{
return $query->result();	
}
else
{
return false;	
}
} 
//delete language
function delete_language1($id)
{
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id',$candidate_id);
$this->db->where('language_id',$id);
$query = $this->db->delete("candidate_language");
if($query)
{
return true;
}
else
{
return false;
}
}
// add languages
public function insert_can_languages($var)
{
$query=$this->db->insert('candidate_language',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code to show the data on edit languse page
public function read_joblanguages_record($pass)
{
$this->db->where($pass);
$query=$this->db->get('languages');
if($query->num_rows()==1)
{
return $query->result();	
}
else
{
return false;	
}
}
//code for update langusges
public function update_can_languages($id,$var)
{	
$candidate_id=$this->session->userdata('user_id');
$this->db->where('candidate_id', $candidate_id);
$this->db->where('language_id', $id);
$query=$this->db->update('candidate_language', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update personal indromation
public function update_per_info_cand($candidate_id,$var)
{	
$this->db->where('user_id', $candidate_id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to search job

public function read_jobs()
{

//$this->db->where('job_id',$job_id);
//$this->db->where('city',$city_state);	
/*$this->db->where("(job_id='".$job_id."' OR city='".$city_state."')");*/

$query = $this->db->get("njobn_jobdetails");
		if($query){
			return $query->result();
		}else{
			return false;
		}
}
	function getCountry(){
		$this->db->select('id,name');
		$this->db->from('countries');
		$this->db->order_by('name', 'asc'); 
		$query=$this->db->get();
		return $query; 
	}
	function getData($loadType,$loadId){
		if($loadType=="state"){
			$fieldList='id,name as name';
			$table='states';
			$fieldName='country_id';
			$orderByField='name';						
		}else{
			$fieldList='id,name as name';
			$table='cities';
			$fieldName='state_id';
			$orderByField='name';	
		}
		
		$this->db->select($fieldList);
		$this->db->from($table);
		$this->db->where($fieldName, $loadId);
		$this->db->order_by($orderByField, 'asc');
		$query=$this->db->get();
		return $query; 
	}
public function insert_shortlistjob($var)
{
$query=$this->db->insert('shot_listjob',$var);
if($query)
{
return true;
}
else
{
return false;
}
}	
//apply job code 
public function apply_job($var)
{
$query=$this->db->insert('candidate_listjobs',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to update users
public function update_usersprofile($id,$var)
{	
$this->db->where('user_id', $id);
$query=$this->db->update('njobn_webusers', $var);
if($query)
{
return true;
}
else
{
return false;
}
}
//code for to deleete job psot
function delete_job_postdelete($id)
{
$this->db->where('job_id',$id);
$query = $this->db->delete("njobn_jobdetails");
if($query)
{
return true;
}
else
{
return false;
}
}
/*Hamza code - advertisements********************/
		
		
		
		public function insert_advert_record($var)
		{
			$query=$this->db->insert('advertisements',$var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
			
		//code for read advertisements
		public function read_advertisements_record()
		{
			
			$query=$this->db->get('advertisements');
			return $query->result();			
		}
		
		//delete code for advertisements
		function delete_advert($table, $id)
		{
			
			$this->db->where('id',$id);
			$query = $this->db->delete($table);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		//code to read specfic record for editing
		public function read_advert_record($pass)
		{
			
			$this->db->where($pass);
			$query=$this->db->get('advertisements');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		//code to edit advert 
		public function update_advert_record($id,$var)
		{	
			$this->db->where('id', $id);
			$query=$this->db->update('advertisements', $var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
			
		}
		
		//code to view single advert record
		public function view_advert_record($pass)
		{
			
			$this->db->where($pass);
			$query=$this->db->get('advertisements');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		
		//code to get image name
		public function get_image_name($position)
		{			
			
			$this->db->where('position', $position);
			$query=$this->db->get('advertisements');
			if($query->num_rows() > 0) 
			{
				$results = $query->result();
				return $results;
				
   		 	}
	}

public function insert_logo_record($var)
		{
			$this->db->from('logo');
			$limit = $this->db->get();
			$rowcount = $limit->num_rows();
			if ($rowcount < 5)
			{
				$query=$this->db->insert('logo',$var);
				if($query)
				{
					return true;
				}
				else
				{
					return false;
				}
				
			}
			else
			{
				return false;
			}
		}
			
		//code for read logo
		public function read_logos_record()
		{
			
			$query=$this->db->get('logo');
			return $query->result();			
		}
		
		
		
		//delete code for logo
		function del_logo($table, $id)
		{
			
			$this->db->where('id',$id);
			$query = $this->db->delete($table);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		//code to read specfic record for editing
		public function read_logo_record($pass)
		{
			
			$this->db->where($pass);
			$query=$this->db->get('logo');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
		//code to edit logo 
		public function update_logo_record($id,$var)
		{	
			$this->db->where('id', $id);
			$query=$this->db->update('logo', $var);
			if($query)
			{
				return true;
			}
			else
			{
				return false;
			}
			
		}
			public function read_all_cv()
		{
			$this->db->Where('user_type', 1);
			$query = $this->db->get('njobn_webusers');
			return $query->result();
		}
		
		//code to view single logo record
		public function view_logo_record($pass)
		{
			
			$this->db->where($pass);
			$query=$this->db->get('logo');
			if($query->num_rows()==1)
			{
				return $query->result();	
			}
			else
			{
				return false;	
			}
		}
	//code for make enetr fiels
		public function insertfiles($data = array())
		{
		$insert = $this->db->insert_batch('files',$data);
		return $insert?true:false;
	    }
//code for to read cvdaabse
public function read_cvdatabse_record()
{
$query=$this->db->get('files');
return $query->result();
}
//code for delete cv databse
function del_cvdatasbe($id)
{
$this->db->where('id',$id);
$query=$this->db->delete('files');
if($query){
echo '<script type="text/javascript">' . "\n";
echo 'window.location="cvbuild";';
echo '</script>';
}
}		
}

