<?php
class FeeModel extends CI_Model {
// public function monthfee(){
// $amount=2717;    
// $class="7";
// $this->db->where("class",$class);
// $table="school_fee_structure";
// $data_array=array("april"=>$amount,"may"=>$amount,"june"=>$amount,"july"=>$amount,"august"=>$amount,"september"=>$amount,"october"=>$amount,"november"=>$amount,"december"=>$amount,"january"=>$amount,"february"=>$amount,"march"=>$amount);
// $this->db->update($table,$data_array);
// echo $this->db->affected_rows();
// }

public function fetch_fee_structure($table){
// $table="school_fee_structure";    
$info=array();
$this->db->select('*');
$this->db->from($table);
$info=$this->db->get()->result_array();
return $info;
}
public function fetch_fee_structure_class($table2,$class_name){
$info=array();
$this->db->select('*');
$this->db->from($table2);
$this->db->where('class',$class_name);
$info=$this->db->get()->result_array();
return $info;    
}

public function student_search($field,$no){
    
$table='student';    
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where($field,$no);

$this->db->where('status',1);

$info=$this->db->get()->result_array();
return $info;    
}


public function fetch_all_student($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('status',1);
$info=$this->db->get()->result_array();
return $info;
}

public function fetch_all_student_inac($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('status','0');
$info=$this->db->get()->result_array();
return $info;
}

public function fetch_single_student($table,$id){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('status',1);
$this->db->where('id',$id);
$info=$this->db->get()->result_array();
return $info;
}
public function fetch_fee_collection($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$info=$this->db->get()->result_array();
return $info;    
}

public function fetch_class_fee($table,$class){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('class',$class);
$info=$this->db->get()->result_array();
return $info;
}   
public function add_fee($data_array,$table){
$this->db->insert($table,$data_array);
return $this->db->insert_id();    
}    
 public function get_fee_invoices($sid){
$info=array();
$this->db->select('*');
      $this->db->from('student_fee');
    //   $this->db->order_by('fee_no');
      $this->db->where('sid',$sid);
      $info=$this->db->get()->result_array();
      return $info;
}    

public function fetch_single_fee_details($fee_no){
$this->db->where('fee_no', $fee_no);
$data = $this->db->get('student_fee');

$output ='';
$logo="";
foreach($data->result() as $row)
{
$sid =$row->sid;
$this->db->where('id', $sid);
$data1 = $this->db->get('student');
foreach($data1->result() as $row1){     
$output .='<div style="height:48%; border:1px solid red">';
$output .='<div style="">
<div style=""><p align="center"><span style="float:left; height:70px"><img src="assets/img/logo.jpg" style="width:70px;height:auto;" /></span>
<span style="height:35px; padding:10px;"><b>'.school_full_name.'<b></span><br>
<span style="height:35px;padding:10px;"><b>'.school_address.'</b></span><br>
<span><b>Invoice No. : SJEC-'.$row->fee_no.'</b></span></p></div>
</div>';
$output .="<div style='border:1px solid red;'></div>";
    
$output .='<table  width="100%" cellspacing="5" cellpadding="5" font-size"13px" >';
$output .='<tr><td style="width:50%;color:red">Scholar No. : '.$row->sch_no.'</td><td style="width:50%;color:red;">Date : '.date("d-m-Y", strtotime($row->fee_date)).'</td></tr>';
$output .= '
<tr>
<td width="30%">Class : '.$row1->class.'-'.$row1->section.'</td>
<td width="70%">Contact No : '.$row1->contact_no.'</td>
</tr>
<tr style=" ">
<td style="width:30%;">Student Name : </td>
<td style=" width:70%;text-transform: uppercase!important;">'.$row1->student_name.'</td>
</tr>

<tr style=" width:100%;">
<td style=" width:30%;">Father Name :</td><td width="70%" style="text-transform: uppercase!important;">'.$row1->father_name.'</td>
</tr>
<tr style=" width:100%;">
<td width="30%" style="width:30%;">Address : </td><td style="text-transform: uppercase!important;">'.$row1->address.'</td>
</tr>
';
      
          

$output .= '
<tr><td >Fee Months:</td><td style="text-transform: uppercase!important;">'.$row->months.'</td></tr>
<tr><td>Total Composit Fee:</td><td>'.$row->estimate_amount.'</td></p><br>
<tr><td>Total Paid:</td><td >'.$row->total_amount.'</td></tr>
';    
          
$output .= '</table>';
$output .="<div style='border:1px solid red;'></div>";
$output .= '<p align="center" width="100%"><span>Fee Reciept : This is computer generated invoice. <b>School Copy</b> </span><br><span>Website: www.sjec.edu.in</span></p>';
$output .='</div>';



// parent Copy

// $this->db->where('fee_no', $fee_no);
// $data = $this->db->get('student_fee');


// $sid =$row->sid;

// $this->db->where('id', $sid);
// $data1 = $this->db->get('student');

$output .="<div style='border-top:1px dotted red;margin-top:10px; height:10px;'></div>";

$output .='<div style="height:48%;border:1px solid red;margin-bottom:5px !important;">';
$output .='<div style="">
<div style="">
<p align="center">
<span style="float:left; height:70px"><img src="assets/img/logo.jpg" style="width:70px;height:auto;" /></span>
<span style="height:35px; padding:10px;"><b>'.school_full_name.'<b></span><br>
<span style="height:35px;padding:10px;"><b>'.school_address.'</b></span><br>
<span><b>Invoice No. : SJEC-'.$row->fee_no.'</b></span></p>
</div>
</div>';
$output .="<div style='border:1px solid red;'></div>";


$output .='<table width="100%" cellspacing="5" cellpadding="5" font-size"13px" >';    
$output .='<tr><td style="width:50%;color:red">Scholar No. : '.$row->sch_no.'</td><td style="width:50%;color:red;">Date : '.date("d-m-Y", strtotime($row->fee_date)).'</td></tr>';
$output .= '
<tr>
<td width="30%">Class : '.$row1->class.'-'.$row1->section.'</td>
<td width="70%">Contact No : '.$row1->contact_no.'</td>
</tr>
<tr style=" ">
<td style="width:30%;">Student Name : </td>
<td style=" width:70%; text-transform: uppercase!important;">'.$row1->student_name.'</td>
</tr>
<tr>
<td style="width:30% !important;">Father Name :</td><td style="text-transform: uppercase!important width:70%;">'.$row1->father_name.'</td>
</tr>
<tr>
<td wiidth="30%" style="width:30% !important;">Address : </td>
<td width="70%" style="text-transform: uppercase !important; width:70% !important;">'.$row1->address.'</td>
</tr>
';

          

$output .= '
<tr><td >Fee Months:</td><td style="text-transform: uppercase!important;">'.$row->months.'</td></tr>
<tr><td>Total Composit Fee:</td><td>'.$row->estimate_amount.'</td></p><br>
<tr><td>Total Paid:</td><td width="50%">'.$row->total_amount.'</td></tr>
';    
      
$output .= '</table>';
$output .="<div style='border:1px solid red;'></div>";
$output .= '<p align="center" width="100%"><span>Fee Reciept : This is computer generated invoice. <b>Parent Copy</b> </span><br><span>Website: www.sjec.edu.in</span></p>';
$output .='</div>';
}
}
return $output;    
}

public function get_single_class_student_data($class,$table){
$table='student';    
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('class',$class);

$this->db->where('status',1);

$info=$this->db->get()->result_array();
return $info;    
}

public function fetch_class_section_student($student_table,$student_class,$section){
$table='student';    
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('class',$student_class);
$this->db->where('section',$section);
$this->db->where('status',1);
$this->db->order_by('roll_no','ASC');
$info=$this->db->get()->result_array();
return $info;      
}
public function get_single_student_fee_data($sid,$table_fee){
$info=array();
$this->db->select('*');
$this->db->from($table_fee);
$this->db->where('sid',$sid);
$info=$this->db->get()->result_array();
return $info;        
}


public function get_date_fee_invoices($fee_date){
$info=array();
$this->db->select('*');
$table ='student_fee';
$this->db->from($table);
$this->db->where('fee_date',$fee_date);
$this->db->order_by("student_class","asc");
$info=$this->db->get()->result_array();
return $info;
}

public function fetch_date_fee_details($date){
$info=array();
$this->db->select('*');
$table ='student_fee';
$this->db->from($table);
$this->db->where('fee_date',$date);
$this->db->order_by("student_class","asc");
$info=$this->db->get()->result_array();
return $info;

}   



public function pdf_header(){
$output ="<html><head>";
$output .='<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
</head><body>';

return $output;
}



public function get_single_student_fee_data1($sid,$table_fee){
$info=array();
$this->db->select('*');
$this->db->from($table_fee);
$this->db->where('sid',$sid);
$this->db->order_by('fee_no',"DESC");
$this->db->limit(1);
$info=$this->db->get()->result_array();
return $info;        
}


public function fetch_single_student_in_fee($table,$id){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('sid',$id);
$info=$this->db->get()->result_array();
return $info;
}

public function all_fee_invoices(){
$info=array();
$this->db->select('*');
$table='student_fee';
$this->db->from($table);
// $this->db->where('status',1);

$this->db->order_by('fee_no',"DESC");

$info=$this->db->get()->result_array();
return $info;    
}


public function fetch_single_student_for_management($table,$id){
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('status',1);
$this->db->where('id',$id);
$info=$this->db->get()->result_array();
return $info;    
}

public function fetch_all_student_for_management($table){
    $info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('status',1);

$info=$this->db->get()->result_array();
return $info;
}

public function today_fee_collection_report($date,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('fee_date',$date);
$info=$this->db->get()->result_array();
return $info;    
}
public function all_fee_collection_report($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('fee_date',$date);
$info=$this->db->get()->result_array();
return $info;        
}
public function all_fee_collection_report_new($table,$acedemic_session){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('acedemic_session',$acedemic_session);
$info=$this->db->get()->result_array();
return $info;        
}

public function all_duplicate_fees(){
$table='student_fee';
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('fee_date',$date);
$info=$this->db->get()->result_array();
return $info;     
}

public function get_count_fee_rows($sid){
$this->db->select('*');
$this->db->from('student_fee');
$this->db->where('sid',$sid);
return $this->db->get()->num_rows();    
}


public function my_class_fee_defaulters($my_class){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('student_class',$class);
$this->db->where('class',$class);

$info=$this->db->get()->result_array();
return $info;    
}


public function check_fee_entry($sid,$schno,$status_1,$status_2,$status_3,$status_4,$status_5,$status_6,$status_7,$status_8,$status_9,$status_10,$status_11,$status_12,$total){
$this->db->select('*');
$this->db->from('student_fee');
$this->db->where('sid',$sid);
$this->db->where('sch_no',$schno);
$this->db->where('january',$status_1);
$this->db->where('february',$status_2);
$this->db->where('march',$status_3);
$this->db->where('april',$status_4);
$this->db->where('may',$status_5);
$this->db->where('june',$status_6);
$this->db->where('july',$status_7);
$this->db->where('august',$status_8);
$this->db->where('september',$status_9);
$this->db->where('october',$status_10);
$this->db->where('november',$status_11);
$this->db->where('december',$status_12);
return $this->db->get()->num_rows(); 
}



public function check_data_exists($fee_for_date){
$table='student_fee';
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('fee_date',$fee_for_date);
$info=$this->db->get()->result_array();
return $info;    
}
}