<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============
extract($_POST);
$branchid = $_SESSION['LOGIN_BRANCH'];

// $res = $obj->View_column_details_By_Cond("_int_institute_setup_vw","DISTINCT(branch_id)","class_id='$class_id'");
// echo $res['branch_id'];


     

if($opr=='add'){

	 $section_ids=$obj->View_All_child($dept_id,'SC');
	 $section_ids="0".$section_ids;
	
	 $fee_type_info = $obj->Details_By_Cond("_int_fee_head", "_id='$fee_head'");
	 $fee_type = $fee_type_info['_fee_type'];
	
		$form_data2=array(
		'_branch_id'=>$branchid,
		'_dept_id'=>$dept_id ,
		'_fee_head_id'=>$fee_head,
		'_fee_amount'=>$amount,
		'_status'=>'A',
		'_entry_by'=>$_SESSION['LOGIN_USERID'],
		'_entry_date'=>date("Y:m:d h:i:s")
		);

	$entry1=$obj->Insert_Data_By_Cond("_int_class_fee_declare", $form_data2,"_dept_id='$dept_id' AND _fee_head_id='$fee_head'");
	
	
	/*
	if ($fee_type=='M')
	{
	foreach($obj->View_colmn_By_Cond("_pf_std_basic_info","_id,_pid","_section_id in (".$section_ids.") ") AS $value)
	{
		
			$std_id=$value['_pid'];
	$form_data3=array(
		'_std_id'=>$std_id,
		'_fee_head_id'=>$fee_head ,
		'_dept_id'=>$dept_id ,
		'_fee_type'=>$fee_type,
		'_fee_amount'=>$amount,
		'_status'=>'A',
		'_entry_by'=>$_SESSION['LOGIN_USERID'],
		'_entry_date'=>date("Y:m:d h:i:s")
		);
		
		
	
	$entry1=$obj->Insert_Data_By_Cond("_pf_student_fee_assign", $form_data3,"_std_id=$std_id AND _fee_head_id='$fee_head'");
	
		

	
	}
	}
	
	*/


}

?>


<?php

if($opr=='update'){

$section_ids=$obj->View_All_child($dept_id,'SC');
	 $section_ids="0".$section_ids;
	
	 $fee_type_info = $obj->Details_By_Cond("_int_fee_head", "_id='$fee_head'");
	 $fee_type = $fee_type_info['_fee_type'];
	
$form_data2=array(
		'_branch_id'=>$branchid,
		'_dept_id'=>$dept_id,
		'_fee_head_id'=>$fee_head,
		'_fee_amount'=>$amount,
		'_status'=>$status,
		'_update_by'=>$_SESSION['LOGIN_USERID'],
		
		);

	$entry1=$obj->Update_Data("_int_class_fee_declare", $form_data2,"_id='$id'");
	
	
	
	/*
	if ($fee_type=='M')
	{
	foreach($obj->View_colmn_By_Cond("_pf_std_basic_info","_id,_pid","_section_id in (".$section_ids.") ") AS $value)
	{
	$form_data3=array(
		'_std_id'=>$value['_pid'],
		'_fee_head_id'=>$fee_head ,
		'_dept_id'=>$dept_id ,
		'_fee_type'=>$fee_type,
		'_fee_amount'=>$amount,
		'_status'=>'A',
		'_entry_by'=>$_SESSION['LOGIN_USERID'],
		'_entry_date'=>date("Y:m:d h:i:s")
		);
		
		
	$std_id=$value['_pid'];
	$entry1=$obj->Update_Data("_pf_student_fee_assign", $form_data3,"_std_id=$std_id AND _fee_head_id='$fee_head'");
	}
	}
	*/


}

?>



<?php

if($opr=='asign_fee_to_studet'){
	$section_ids=$obj->View_All_child($dept_id,'SC');
	$section_ids="0".$section_ids;
	
	$fee_type_info = $obj->Details_By_Cond("_int_fee_head", "_id='$fee_head'");
	$fee_type = $fee_type_info['_fee_type'];
	
	if($fee_type=='M'){
		$table_name="_pf_std_basic_info pbf LEFT JOIN _pf_std_personal_info psf ON pbf._pid=psf._id";
		$where_cond = "pbf._section_id IN (".$section_ids.") AND pbf._session='$year' AND psf._status='A'";
		foreach($obj->View_colmn_By_Cond($table_name,"pbf._pid",$where_cond) AS $value){
			$std_id=$value['_pid'];
			//$sec_id=$value['_section_id'];
			$form_data3=array(
							'_std_id'=>$std_id,
							'_fee_head_id'=>$fee_head,
							'_dept_id'=>$dept_id,
							'_fee_type'=>$fee_type,
							'_fee_amount'=>$amount,
							'_status'=>'A',
							'_year'=>$year,
							'_entry_by'=>$_SESSION['LOGIN_USERID'],
							'_entry_date'=>date("Y:m:d h:i:s")
						);
		
			$entry1=$obj->Insert_Data_By_Cond("_pf_student_fee_assign", $form_data3,"_std_id=$std_id AND _fee_head_id='$fee_head' and _year=$year");
		}
	}
}

?>




<?php

if($opr=='update_student_asign_fee'){
	$section_ids=$obj->View_All_child($dept_id,'SC');
	$section_ids="0".$section_ids;
	
	$fee_type_info = $obj->Details_By_Cond("_int_fee_head", "_id='$fee_head'");
	$fee_type = $fee_type_info['_fee_type'];
	$fee_status = $fee_type_info['_status'];
	$form_data2=array(
		'_dept_id'=>$dept_id,
		'_fee_amount'=>$amount,
		'_status'=>$fee_status,
		'_update_by'=>$_SESSION['LOGIN_USERID'],
		'_last_update'=>date("Y:m:d h:i:s")
		);

	$entry12=$obj->Update_Data("_int_class_fee_declare", $form_data2,"_id='$id'");
	
	if ($fee_type=='M'){
		$table_name="_pf_std_basic_info pbf LEFT JOIN _pf_std_personal_info psf ON pbf._pid=psf._id";
		$where_cond = "pbf._section_id IN (".$section_ids.") AND pbf._session='$year' AND psf._status='A'";
		foreach($obj->View_colmn_By_Cond($table_name,"pbf._pid",$where_cond) AS $value){
			$std_id=$value['_pid'];
			$form_data3=array(
							'_std_id'=>$std_id,
							'_fee_head_id'=>$fee_head ,
							'_dept_id'=>$dept_id ,
							'_fee_type'=>$fee_type,
							'_fee_amount'=>$amount,
							'_status'=>'A',
							'_update_by'=>$_SESSION['LOGIN_USERID'],
							'_update_date'=>date("Y:m:d h:i:s")
						);
			
			$entry1=$obj->Update_Data("_pf_student_fee_assign", $form_data3,"_std_id=$std_id AND _fee_head_id='$fee_head' and _year=$year");
		}
	}
}

?>



<?php

if($opr=='delete_student_asign_fee'){

$section_ids=$obj->View_All_child($dept_id,'SC');
	 $section_ids="0".$section_ids;
	
	 $fee_type_info = $obj->Details_By_Cond("_int_fee_head", "_id='$fee_head'");
	 $fee_type = $fee_type_info['_fee_type'];
	
	
	
	
	
	if ($fee_type=='M')
	{
	foreach($obj->View_colmn_By_Cond("_pf_std_basic_info","_id,_pid","_section_id in (".$section_ids.") ") AS $value)
	{
	$form_data3=array(
		'_std_id'=>$value['_pid'],
		'_fee_head_id'=>$fee_head ,
		'_dept_id'=>$dept_id ,
		'_fee_type'=>$fee_type,
		'_fee_amount'=>$amount,
		'_status'=>'A',
		'_entry_by'=>$_SESSION['LOGIN_USERID'],
		'_entry_date'=>date("Y:m:d h:i:s")
		);
		
		
	$std_id=$value['_pid'];
	$entry1=$obj->Delete_Data("_pf_student_fee_assign", $form_data3,"_std_id=$std_id AND _fee_head_id='$fee_head'");
	}
	
	
	}
	
	echo "delete successfully";
	


}

?>



<div class="row-fluid" style="margin-top: 15px;">
								
								
	<table id="sample-table-121" class="table table-striped table-bordered table-hover">
		<thead>
			<th>Sl</th>
			<th>Shift</th>
			<th>Medium</th>
			<th>Class</th>
			<th>Department</th>
			<th>Fee Head</th>
			<th>Amount</th>
			<th>Type</th>
			
			<th>Status</th>
			<th>Action</th>
		</thead>
		<tbody>
			
			<?php

			$i='0';
			foreach($obj->View_fee_assign_Cond("fd._branch_id='$branchid'") AS $value1){
			$i++;
			extract($value1);
			?>
			<tr>
				<td><?php echo $i; ?></td>
				<td><?php echo $value1['_sh_name']; ?></td>
				<td><?php echo $value1['_me_name']; ?></td>
				<td><?php echo $value1['_cl_name']; ?></td>
				<td><?php echo $value1['_dp_name']; ?></td>
				<td><?php echo $value1['_fee_head']; ?></td>
				<td><?php echo $value1['_fee_amount']; ?></td>
				<?php if ($value1['_fee_type']=='M') {?>
				<td>Monthy</td>
				<?php }else{ ?>
				<td>Others</td>				
				<?php }?>
				
				<td><?php if($value1['_status']=='A'){echo 'Active'; } else{echo 'Inactive';} ?></td>
				
				<td>
					<?php if($_SESSION['edit']=='Y'){ ?>
					<!--<i class="icon-edit bigger-170" style="hover:cursor;" href="#modal-table" data-toggle="modal" onclick="show_edit_view(<?php echo $value1['_id']; ?>)"></i>&nbsp;&nbsp;-->
				  
					<button class="btn btn-success  btn-mini" onclick="show_edit_view(<?php echo $value1['_id']; ?>)" data-toggle="modal" data-target="#modal-table" >Edit</button>&nbsp;
					<!--<button class="btn btn-info btn-mini" onclick="fee_partial_pay('<?php echo $master_invoice_id; ?>')" data-toggle="modal" data-target="#myModal">Partial Pay</button>&nbsp;-->
											

				  
					<?php } 
					
					
				 if ($value1['_fee_type']=='M'){
					?>
					
				
					
					<button class="btn btn-info btn-mini" onclick="show_std_fee_asign_view(<?php echo $value1['_id']; ?>)" data-toggle="modal" data-target="#modal-table1">Fee Asign</button>
				 <?php }?>
					
				</td>
			</tr>
			<?php } ?>
			
		</tbody>	

	</table>
</div>



<script type="text/javascript">	
var oTable2 = $('#sample-table-121').dataTable( {
"aoColumns": [
  { "bSortable": true },
  null, null,null,null,null,null,null,null,
  { "bSortable": true }
] } );
				
</script>