<?php
session_start();
// ============
include("../../php_crud/my_class.php");
$obj=new my_class();
$br_id = $_SESSION['LOGIN_BRANCH'];
// ============
extract($_REQUEST);


$section_name = $obj->Details_By_Cond("_int_institute_setup","_id='$section_id'");
extract($section_name);

$department_name = $obj->Details_By_Cond("_int_institute_setup","_id='$department_id'");
extract($department_name);

$class_name = $obj->Details_By_Cond("_int_institute_setup","_id='$class_id'");
extract($class_name);

$shift_name  = $obj->Details_By_Cond("_int_institute_setup","_id='$shift_id '");
extract($shift_name);

$medium_name  = $obj->Details_By_Cond("_int_institute_setup","_id='$medium_id'");
extract($medium_name );

$student_type_name  = $obj->Details_By_Cond("_int_institute_setup","_id='$student_type_id'");
extract($student_type_name );


function getMonthName($i)
{
    if($i=="1") { return "January";}
    else if($i=="2") { return "February";}
    else if($i=="3") { return "March";}
    else if($i=="4") { return "April";}
    else if($i=="5") { return "May";}
    else if($i=="6") { return "June";}
    else if($i=="7") { return "July";}
    else if($i=="8") { return "August";}
    else if($i=="9") { return "September";}
    else if($i=="10") { return "October";}
    else if($i=="11") { return "November";}
    else if($i=="12") { return "December";}
    else { return "Unknown";}
}

?>
<style type="text/css">
i{
	cursor:pointer;
}

</style>
<script src="module/fees/js/monthly_fee_rollback.js" type="text/javascript"></script>

<input type="hidden" id="branch_id" value="<?php echo $branch_id; ?>">
<input type="hidden" id="shift_id" value="<?php echo $shift_id; ?>">
<input type="hidden" id="medium_id" value="<?php echo $medium_id; ?>">
<input type="hidden" id="class_id" value="<?php echo $class_id; ?>">
<input type="hidden" id="department_id" value="<?php echo $department_id; ?>">
<input type="hidden" id="std_month" value="<?php echo $std_month; ?>">
<input type="hidden" id="session" value="<?php echo $session; ?>">

<div class="row-fluid" id="form_data" >


<div class="widget-box2">
										<div class="widget-header header-color-green2">
											<h4 class="smaller" >
												<small style="color:#fff;">Monthly Fee Rollback Information </small>
											</h4>
											
											<span style="text-align:right; float:right; ">

            
          <a href="#" id="back_table" class=" btn btn-primary btn-small" style="padding:3px;"><i class="icon-arrow-left icon-on-left"></i> BACK </a>
					</span>
											
													
										</div>

										<div class="widget-body">
											<div class="widget-main">
												<p> 
													 			 
															
													<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Shift:</b> '.$shift_name['_name'];?></span> 
													<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Class:</b> '.$class_name['_name']; ?></span> 
													<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Department:</b> '.$department_name['_name'];?></span> 
													<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Month:</b> '.getMonthName($std_month);?></span>
													<span style="font-size:11px;" class="alert alert-success inline no-margin"><?php echo '<b>Session:</b> '.$session;?></span>

													


													
													<div id="mark_details_info"></div>		
													 
												</p> 
												 												
											</div>
										</div>
									
									</div>


</div>





<input type="hidden" id="dept_id" value="<?php echo $department_id; ?>"/>

<div class="row-fluid" style="margin-top: 10px;" id="table_holder">


	<table id="sample-table-22" class="table table-striped table-bordered table-hover">

		<thead>
			<th>Sl</th>
			<th>Student Id</th>
            <th>Roll</th>
			<th>Student Name</th>
			<th>Contact Mobile</th>
<!--			<th>Invoice No</th>-->
			<th>Total Amount</th>
			<th>Due Amount</th>
			<th>Paid Amount</th>
			<th>Discount</th>
			<th style="width: 87px;">Status</th>
			<th style="width: 114px;">Action</th>
		</thead>
		<tbody>
			<?php
//           View_All_child
//           `_fee_total_receive`
//          `_fee_master_invoice`
//          `_fee_partial_pay_table`
//          _fee_details_invoice
			$where="";

            if($department_id!="")
            {
                $section_list= $obj-> View_All_child($department_id,"SC");
            }
            else if($department_id=="" && $class_id!="")
            {
                $section_list= $obj-> View_All_child($class_id,"SC");
            }
            else if($department_id=="" && $class_id=="" && $medium_id!="")
            {
                $section_list= $obj-> View_All_child($medium_id,"SC");
            }
            else if($department_id=="" && $class_id=="" && $medium_id=="" && $shift_id!="")
            {
                $section_list= $obj-> View_All_child($shift_id,"SC");
            }


            $student_status="A";
			if($student_status!='all'){
				$where .= "pf_std._status='$student_status' and ";
			}
			if($student_status=='all'){
				$where .= "pf_std._status!='D' and ";
			}
			$where.="bsf._session='$session' and ";

			 if($section_list != '')
			 {
			     $where .= "bsf._section_id IN (0$section_list)  ORDER BY pf_std._section_roll";
			 }
//            SELECT * FROM `_pf_std_personal_info` pf_std
//LEFT JOIN `_pf_std_basic_info` bsf  ON bsf.`_pid`=pf_std.`_id`
//LEFT JOIN `_fee_master_invoice` fmi ON fmi.`_std_id`=pf_std.`_id` AND fmi.`_year`='2018' AND fmi.`_month`='1'
// WHERE bsf._section_id IN (156,157,158,159,160,161) AND bsf.`_session`='2018'

			 //print_r($_REQUEST);


            $table_name="`_pf_std_personal_info` pf_std LEFT JOIN `_pf_std_basic_info` bsf  ON bsf.`_pid`=pf_std.`_id` LEFT JOIN `_fee_master_invoice` fmi ON fmi.`_std_id`=pf_std.`_id` AND fmi.`_year`='$session' AND fmi.`_month`='$std_month'";
            $column="`_uniq_id`,`_section_roll`,`_full_name`,`_contact_mobile`,`_invoice_no`,`_total_amount`,`_due_amount`,`_paid_amount`,fmi.`_status`,fmi.`_id` master_invoice_id,_discount";
            $where_cond=$where;

			//echo $where;
							$sl=0;
							function chekval($int)
                            {if($int=="") {return 0;} else{return trim($int);}}
                            function chekstring($str)
                            {if($str=="" || $str==NULL) {return "Unknown";} else{return trim($str);}}
							foreach($obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond) AS $value1){
                                extract($value1);
                                //echo "<pre>";
                                //print_r($value1);
                                //$getstdfee=$obj->View_colmn_By_Cond('_pf_student_fee_assign','SUM(_fee_amount) totalfee', "_std_id='".$value1['_std_id']."' ");
                                $master_invoice_id=$value1['master_invoice_id'];
                                $nstatus="Unknown";
                                if($value1['_status']=="U")
                                {
                                    $nstatus="<button class='btn btn-mini btn-danger disabled '>Unpaid</button>";
                                }
                                else if($value1['_status']=="P")
                                {
                                    $nstatus="<button class='btn btn-mini btn-success disabled '>Paid</button>";
                                }
                                else if($value1['_status']=="PR")
                                {
                                    $nstatus="<button class='btn btn-mini btn-info disabled '>Partially Paid</button>";
                                }

                                $sl++;
								echo "<tr>";
								echo "<td>".$sl."</td>";
								echo "<td>".chekstring($value1['_uniq_id'])."</td>";
								echo "<td>".chekstring($value1['_section_roll'])."</td>";
								echo "<td>".chekstring($value1['_full_name'])."</td>";
								echo "<td>".chekstring($value1['_contact_mobile'])."</td>";
//								echo "<td>".chekstring($value1['_invoice_no'])."</td>";
								echo "<td>".chekval($value1['_total_amount'])."</td>";
								echo "<td>".chekval($value1['_due_amount'])."</td>";
								echo "<td>".chekval($value1['_paid_amount'])."</td>";
								echo "<td>".chekval($value1['_discount'])."</td>";
								echo "<td>".$nstatus."</td>";




								echo '<td>';
										if($_SESSION['view']=='Y'){
										?>
										    <button class="btn btn-success  btn-mini" onclick="fee_monthly_edit('<?php echo $master_invoice_id; ?>')" data-toggle="modal" data-target="#myModal" >Edit</button>&nbsp;<button class="btn btn-danger btn-mini" onclick="fee_rollback('<?php echo $master_invoice_id; ?>')" data-toggle="modal" data-target="#myModal">Rollback</button>&nbsp;
            <?php
										}
										if($_SESSION['edit']=='Y'){

                                        }

									echo '</td>';
								echo "</tr>";
							 } 
				 
			?>
		</tbody>	

	</table>
	<div>
</div>
</div>
<div class="row-fluid" id="part2">
         
      
</div>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog" style="width: 750px">
    <div class="modal-dialog modal-lg">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" >&times;</button>
                <h4 class="modal-title">Monthly Fee Rollback</h4>
            </div>


                <div id="resultDiv"></div>

<!--            <div class="modal-footer">-->
<!--                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>-->
<!--            </div>-->
        </div>

    </div>
</div>
<script type="text/javascript">

$('#back_table').click(function(){

	$("#main_content_div").load("module/fees/monthly_fee_rollback.php");
	
				
    });	

	






</script>



<script type="text/javascript">


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