<?php include("parent/callMe.php"); ?>

<?php  include("sessioncheck.php"); ?>

<?php


/*// Get the values from the input fields
$fromDate = "2023-06";
$toDate = "2024-02";

// Create DateTime objects for the from and to dates
$fromDateTime = new DateTime($fromDate);
$toDateTime = new DateTime($toDate);

// Create an array to store the month-year values
$months = [];

// Loop through the dates and add the month-year values to the array
while ($fromDateTime <= $toDateTime) {
    $monthYear = $fromDateTime->format('Y-m');
    $months[] = $monthYear;

    // Move to the next month
    $fromDateTime->add(new DateInterval('P1M'));
}

// Print the resulting array
print_r($months);*/
//===============================================================================================

$branchID=$_SESSION['branch'];
$sql2 = "SELECT MAX(CAST(receipt_no AS UNSIGNED)) AS recpt_no FROM eduportal_challan_fee_receiving WHERE branch_id='$branchID' ";

$evt1 =$m->query($sql2);
$prev1= $evt1[0]['recpt_no'];

$reciptNo=$prev1+1;



$sql3 = "SELECT MAX(CAST(settellment_no AS UNSIGNED)) AS settellment_no FROM eduportal_challan_fee_settlement WHERE branch_id='$branchID' ";

$evt =$m->query($sql3);
$prev= $evt[0]['settellment_no'];

$settellmentNo=$prev+1;




$m->where("user_id", $_SESSION['user_id']);

$m->where ("branch_id", $_SESSION['branch']);

$m->where("page_id", 23);

$access = $m->get("users_privilege_detail");





   $branch=$_SESSION['branch'];



     // $session2;

     //  if($_REQUEST['session']!=NULL){



     //   $session2=$_REQUEST['session'];

     // }else {

     //   $session2=$_SESSION['current_session'];

     // }


     $year;

      if( isset($_REQUEST['year'])){

       $year=$_REQUEST['year'];

     }else {

       $year=date("Y");

     }



    if($_REQUEST['student']!=NULL){



       $m->where("status", '0');

       $m->where("branch_id", $_SESSION['branch']);

       $m->where("student_id", $_REQUEST['student']);

       $WorkAssignListVal = $m->get("edu_student_details");



      }

     // print_r($WorkAssignListVal)



      $m->where("student_id", $WorkAssignListVal[0]['student_id']);

      $m->where("class_id", $WorkAssignListVal[0]['class_id']);    

      $m->where("year", $year);

      $m->where("branch_id", $_SESSION['branch']);

      $details2 = $m->get("eduportal_student_fee_structure");


    // print_r($details);


      $m->where("class_id", $WorkAssignListVal[0]['class_id']);

      $class=$m->get("edu_class_config");



      $m->where("section_id", $WorkAssignListVal[0]['section_id']);

      $section=$m->get("edu_adm_section_detail");



      $m->where("session_id", $WorkAssignListVal[0]['session_id']);

      $session=$m->get("edu_session_config");



      $m->where("branch_id", $_SESSION['branch']);

      $branch_details = $m->get("edu_branch_config");



    // settings month details



    $default;



    if($_GET["month"]!=NULL ){

      $default= $_GET["month"];

    }

    else{

      $default= date("m");

    }



      $m->where("Month_Id", $default);

      $month_name=$m->get("eduportal_month_config");





      $m->where("user_id", $_SESSION['user_id']);

      $user_designation=$m->get("edu_user_config");



      $reqFeeRemarks;

      if($brid[0]['prefix_paid_remarks']!=NULL){



        $reqFeeRemarks = "required";

      } else {

        $reqFeeRemarks = "";

      }


$m->where("class_id", $WorkAssignListVal[0]['class_id']);
$m->where("branch_id", $_SESSION['branch']);
$details = $m->get("eduportal_class_fee_details");
     ?>



<!DOCTYPE html>

<html lang="en">

  <head>



    <title>Pay Student Fee | EduPortal</title>

    <?php include('RootMe/css_links.php');?>



<style>



.thStyle{background-color:#337ab7;color:white;}





#paid_table tr th {padding:1.2%;border:1px solid white;font-size: 15px;}

#paid_table tr td {padding:.5%;color: black;font-size: 15px;}







tr th {padding:7px;border:1px solid white;}

tr td {padding:.5%;color: black;}



@media only screen and (max-width: 768px) {



/* For mobile phones: */

.popup_style{margin-top:20%;}



.tabWidth{width:100%;}



.nameHeadingWidth{width:80%;}



.nameHeadingFont{font-size: 12px;}



.SearchNameWidth{width:100%;}



.fontpopupheading{font-size: 12px;}



.picture{display: none;}



}



 @media (min-width:801px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */



    .nameHeadingWidth{width:50%;}

    .nameHeadingFont{font-size: 20px;}

    .SearchNameWidth{width:60%;}





}



.center {

  margin-left: auto;

  margin-right: auto;

}







.textblink{

        color:yellow;

        animation:blinkText 1s  infinite;

    }

    @keyframes blinkText {

        0%{opacity:0.1;}

    50%{opacity:1; text-shadow: 1px 0px 30px yellow;}

    100%{

        opacity:0.1;

    }

    }



</style>

  </head>



<script>

function showResult1(str) {

  if (str.length==0) {

    document.getElementById("livesearch1").innerHTML="";

    document.getElementById("livesearch1").style.border="0px";

    return;

  }

  if (window.XMLHttpRequest) {

    // code for IE7+, Firefox, Chrome, Opera, Safari

    xmlhttp=new XMLHttpRequest();

  } else {  // code for IE6, IE5

    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

  xmlhttp.onreadystatechange=function() {

    if (this.readyState==4 && this.status==200) {

      document.getElementById("livesearch1").innerHTML=this.responseText;

      document.getElementById("livesearch1").style.border="1px solid #A5ACB2";

      //alert(this.responseText);

    }

  }

  xmlhttp.open("GET","livesearch_std_profile.php?q="+str,true);

  xmlhttp.send();

}

</script>



<script>



function PayFullFee() {



 // others fee parameters

 var date=document.getElementById("date").value;

 var month=document.getElementById("month").value;

 //alert(date);

// general parameters to submit the fee



 var student=document.getElementById("student").value;

 var month_name=document.getElementById("month_name").value;

 var fine=document.getElementById("fine").value;

 var challan_id=document.getElementById("challan_id").value;

 var fee_recv_sms=document.getElementById("fee_recv_sms").value;

 var double_sms=document.getElementById("double_confirmation_sms_to_principal").value;

 var std_name=document.getElementById("std_name").value;

 var std_no=document.getElementById("std_no").value;

 var Owner_no=document.getElementById("Owner_no").value;

 var totalAmount=document.getElementById("totalAmount").value;

 var collected=totalAmount;



  // alert(challan_id);



    if (window.XMLHttpRequest) {

      xmlhttp=new XMLHttpRequest();

    } else { // code for IE6, IE5

      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

  xmlhttp.onreadystatechange=function() {



      if (xmlhttp.readyState==4 && xmlhttp.status==200) {



       if(xmlhttp.responseText=="1" || xmlhttp.responseText==1){



         // alert(xmlhttp.responseText);



          document.getElementById("paynow").style.display="none";

          document.getElementById("pay").style.display="none";

          document.getElementById("fullpaid").style.display="block";

//alert("786");

          document.getElementById("paid_fee").innerHTML=totalAmount;



          // div empty text

          var div = document.getElementById('remaining_fee');

          while(div.firstChild){

              div.removeChild(div.firstChild);

          }

          document.getElementById("remaining_fee").innerHTML="0";

         //alert(xmlhttp.responseText);

       }// ending main if condition



      }



    }



  xmlhttp.open("GET","PayFullFee.php?action=PayChallan&collected="+collected+"&challan_id="+challan_id+"&fee_recv_sms="+fee_recv_sms+"&double_confirmation_sms_to_principal="+double_sms+"&student="+student+"&fine="+fine+"&std_name="+std_name+"&std_no="+std_no+"&Owner_no="+Owner_no+"&totalAmount="+totalAmount+"&paid_date="+date+"&month="+month+"&month_name="+month_name+"&student="+student,true);



  xmlhttp.send();



}





function total_received(id) {





      var netTotal=document.getElementsByName("feerec[]");



      var net=0;



      for(i=0;i<netTotal.length;i++){



  if(netTotal[i]!="" || netTotal[i]!=null){





   net= parseInt(net)+ parseInt(netTotal[i].value);



  }



}//ending loop



if(net!=null || net!="" ){

  //alert(net);

  document.getElementById("totaltotal").value=net;

 }





      }





function FamilyData(studentid,cell_no)

    {

     // alert(studentid+"=="+cell_no);

//total_received(id);



        mySelectFunction(studentid);



        var ajx;  // The variable that makes Ajax possible!



        if (window.XMLHttpRequest)

            ajx = new XMLHttpRequest();

        ajx.onreadystatechange = function ()

        {

          //alert("786");

            if (ajx.readyState == 4)

            {

               // alert(ajx.responseText);

                document.getElementById("myID"+studentid).innerHTML = ajx.responseText;



            }

        }



        ajx.open("GET", "get_family_data.php?student_id="+studentid+"&cell_no="+cell_no);

        ajx.send();



    }





     function FamilyDataWithCode(studentid,familycode)

    {

     // alert(studentid+"=="+familycode);

//total_received(id);



        mySelectFunction(studentid);



        var ajx;  // The variable that makes Ajax possible!



        if (window.XMLHttpRequest)

            ajx = new XMLHttpRequest();

        ajx.onreadystatechange = function ()

        {

          //alert("786");

            if (ajx.readyState == 4)

            {

               // alert(ajx.responseText);

                document.getElementById("myID"+studentid).innerHTML = ajx.responseText;



            }

        }



        ajx.open("GET", "get_family_data_withcode.php?student_id="+studentid+"&family_code="+familycode);

        ajx.send();



    }





    function mySelectFunction(studentid) {



  var x = document.getElementById("myID"+studentid);

  if (x.style.display === "none") {

    x.style.display = "block";

  } else {

    x.style.display = "none";

  }

}





// Every time a modal is shown, if it has an autofocus element, focus on it.

$('.modal').on('shown.bs.modal', function() {

  $(this).find('[autofocus]').focus();

});







function getInstallmentData(str)

{



var clsid=document.getElementById("clsid").value;

var stdid=document.getElementById("stdid").value;

   if(str=="")

      alert("Please select any Installment");

  else

     var ajx;  // The variable that makes Ajax possible!

  

  if(window.XMLHttpRequest)

  ajx=new XMLHttpRequest();

  ajx.onreadystatechange = function()

  {



    if(ajx.readyState == 4)

    {

          // alert(ajx.responseText); 

          var vars=ajx.responseText.split(",");

          document.getElementById("duedateinstallment").value= vars[0];

          document.getElementById("installment_fee").value= vars[1];

          //alert(vars[0]);

    }

  }

  ajx.open("GET", "get_installment_data.php?month_id="+str+"&clsid="+clsid+"&stdid="+stdid);

  ajx.send(); 



}









function changeFeePlan(id){

//alert(id);

  var stdid=document.getElementById("stdid").value;

  var clsid=document.getElementById("clsid").value;

  var sessid=document.getElementById("stdSessionid").value;



    if (window.XMLHttpRequest) {



      // code for IE7+, Firefox, Chrome, Opera, Safari



      xmlhttp=new XMLHttpRequest();



    } else { // code for IE6, IE5



      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");



    }



    xmlhttp.onreadystatechange=function() {

//alert(xmlhttp.responseText);

      /*if (xmlhttp.readyState==4 && xmlhttp.status==200) {



        document.getElementById("txt_section").innerHTML=xmlhttp.responseText;

        // alert(xmlhttp.responseText);



      }*/



    }



     xmlhttp.open("GET","get_change_fee_status.php?fee_status="+id+"&student="+stdid+"&clsid="+clsid+"&sessid="+sessid,true);



    xmlhttp.send();





    location.reload();



  }


function monthCalculate(id) {
  
 
   var month = document.getElementById("month_id_from").value;
   var monthlyFee = document.getElementById("stdFee").value;
  
   const fromMonth = month.split("-");
   const toMonth = id.split("-");   
  
  var monthDiffrence = toMonth[1]-fromMonth[1];

  var totalMonth = monthDiffrence+1;

  var totalMonthFee = totalMonth * monthlyFee;

  document.getElementById("1").value=totalMonthFee;
  document.getElementById("total_amt").value=totalMonthFee;
}


   function StudentInstallment(str)

    {

      //alert(str);



       var pkgAmount=document.getElementById("pkgAmount").value;

     

        var ajx;  // The variable that makes Ajax possible!



        if (window.XMLHttpRequest)

            ajx = new XMLHttpRequest();

        ajx.onreadystatechange = function ()

        {

          //alert("786");

            if (ajx.readyState == 4)

            {

              //  alert(ajx.responseText);  

                document.getElementById("myID").innerHTML = ajx.responseText;



            }

        }

        

        ajx.open("GET", "get_student_installment_no.php?insttallmentNo="+str+"&pkgAmount="+pkgAmount);

        ajx.send();



    }


 function updateScholarship(fee) {

      
        var standaredFee=document.getElementById("class_standared_fee").value;
   
        var scholarship = standaredFee-fee;
     
        document.getElementById("std_scholarship").value=scholarship;
       
    }



 </script>



 <!-- jQuery -->

    <script src="js/ajax_functions.js"></script>

  <body class="nav-md">

    <div class="container body">

      <div class="main_container">

        <div class="">



            <?php //include('RootMe/sidebar.php');?>



              <?php //include('RootMe/header.php');?>



        <!-- page content -->

          <div class="" role="main" style="margin-left: 25px;margin-right: 25px;">

          <div class="" style="background-color: white;">



            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; Pay Fee



  <br><br>



  <input type="hidden" name="stdid" id="stdid" value="<?php echo $WorkAssignListVal[0]['student_id'];?>">

   <input type="hidden" name="stdSessionid" id="stdSessionid" value="<?php echo $WorkAssignListVal[0]['session_id'];?>">

<input type="hidden" name="clsid" id="clsid" value="<?php echo $WorkAssignListVal[0]['class_id'] ;?>">



 



          <h3 style="text-align: center;color:#337ab7;">Pay/Receive Student Fee</h3>

          <div class="center" style="width: 100%;text-align: center;">



            <a href="dashboard.php" target="_blank" class="btn btn-primary tabWidth"> Admin Dashboard</a>

            <a href="basic_dashboard.php" target="_blank" class="btn btn-primary tabWidth">Staff Dashboard</a>

            <a href="CreateClassWiseChallan.php" target="_blank" class="btn btn-primary tabWidth"> Create Challan</a>

            <a href="view_challan.php" target="_blank" class="btn btn-primary tabWidth"> View Challan</a>

            <a href="multi_fee_reports.php" target="_blank" class="btn btn-primary tabWidth"> Multi Fee Reports</a>

            <!-- <a href="fee_settings.php" target="_blank" class="btn btn-primary tabWidth"> ClassWise Update Fee</a> -->

            <a href="student_profile.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&student=<?php echo $WorkAssignListVal[0]['student_id'];?>" target="_blank" class="btn btn-primary tabWidth"> Student Profile</a>



            <!-- <a href="print_monthly_fee_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&std=<?php echo $WorkAssignListVal[0]['student_id'];?>&session=<?php echo $_REQUEST['session'];?>&month=<?php echo $_GET['month'][0]['Month_Name'];?>" target="_blank" class="btn btn-primary tabWidth" target="_blank"> Print Fee History</a> -->



            <a data-toggle="modal" data-target="#FeeHistory<?php echo $WorkAssignListVal[0]['student_id'];?>" href="#" class="btn btn-primary tabWidth">Print Fee History

                </a>



           <!--  <a href="pay_fee_test.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&student=<?php echo $WorkAssignListVal[0]['student_id'];?>" target="_blank" class="btn btn-primary tabWidth"> New Pay Fee</a>



            <a href="check_pay_fee.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&student=<?php echo $WorkAssignListVal[0]['student_id'];?>"  class="btn btn-success tabWidth textblink">Pay Fee New Version</a> -->



          </div>







           <!-- Modal -->

  <div id="FeeHistory<?php echo $WorkAssignListVal[0]['student_id'];?>" class="modal fade" role="dialog">

    <div class="modal-dialog">



      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title" style="color:#337ab7;text-align: center; "> Student Fee History </h4>

        </div>





        <div class="modal-body">





        <h4 style="text-align: center;" class="fontpopupheading"> <?php echo $WorkAssignListVal[0]['first_name'];?> | <?php echo $WorkAssignListVal[0]['last_name'];?>

          | <?php echo $class[0]['Class_Name']."-".$section[0]['section_name']." | ".$WorkAssignListVal[0]['candidate_roll_no']." | ".$WorkAssignListVal[0]['ref_no'];?>



        </h4>





      </div>





      <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">





        <input type="hidden" name="action" value="FeeHistory">

        <input  type="hidden" name="studentid" value="<?php echo $WorkAssignListVal[0]['student_id']; ?>"/>





        <div class="col-md-12" >





          <div class="form-group ">

                  <label class="required">Year</label>

          <select name="year" class="form-control" >


              <?php



               $year;

                if(!isset($_REQUEST['year'])){

                  $year=date("Y");

                }else { $year=$_REQUEST['year']; }



              for ($i=2020; $i < 2040; $i++) 

              { ?>

                 <option <?php if($year==$i){echo 'selected';}?> value="<?php echo $i; ?>"><?php echo $i; ?></option>


                      <?php

              } ?>



          </select>

                </div>






                <table>



              <div class="col-md-12">



               <?php



                    $m->orderBy("Month_Id","asc");

                    $SelectMonths = $m->get("eduportal_month_config");



                  foreach($SelectMonths as $SelectMonth) { ?>

                   <tr>

                <div class="col-md-6" >

                  <div class="form-group" >

                  <label class="container1">

                    <input type="checkbox" name="months[]" checked value="<?php echo $SelectMonth['Month_Id'];?>" />

                    <span style="font-size:12px;"><?php echo " ".$SelectMonth['Month_Name'];?></span> <span class="checkmark"></span>

                  </label>

                  <?php } ?>

                  </div>

                </div>

              </tr>

            </div>



              </table>











        </div>









            <div class="modal-footer">



              <button type="submit" class="btn btn-primary" name="submit" >Submit </button>

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





            </div>



          </form>







          </div>



        </div>

      </div>



      <!-- ending -->



<section class="add_sub_agent" id="table_sub_agent">

  <div class="container">



 <div class="" style="margin-top:10px;">



        <div class="panel">

             <div class="panel-heading" id="std_section">



<div class="center nameHeadingWidth" style="width: 100%;text-align: center;">

<?php if($_GET['student']!=NULL){ ?>



<span  class="nameHeadingFont"> Fee History: &nbsp; <?php echo $WorkAssignListVal[0]['first_name']." | ".$WorkAssignListVal[0]['last_name']." | ".$class[0]['Class_Name']."-".$section[0]['section_name']." | ".$WorkAssignListVal[0]['candidate_roll_no']." | ".$WorkAssignListVal[0]['ref_no'];?> </span>



<?php } else { ?>



   <div class="alert alert-danger" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Caution!</strong> Please search student to view fee details!!!

    </div>



<?php } ?>



</div>



<div class="center SearchNameWidth" style="margin-top: 40px;">



            <div class="col-md-6 col-xs-12">

            <?php if ($brid[0]['feature_block']=="0") { ?>

               <form>

                <!-- <label> Search Student</label> -->

                <input type="text" class="form-control" placeholder="Enter | Name | Father Name | Roll No | Admission No" onkeyup="showResult1(this.value)" value="<?php echo $_GET['qr'];?>">

                <div id="livesearch1"></div>

              </form>

           <?php  } else { ?>



              <div class="alert alert-danger" style="width:138%; margin-left: -39%;" id="msg">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

              <strong>Danger!</strong> <?php echo $brid[0]['feature_service_remarks'] ;?>

            </div>



           <?php } ?>

             



              <br>

             </div>




<!-- 
              <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="session" />
              <input type="hidden" value="<?php echo session_id().session_id().session_id().session_id().session_id(); ?>" name="year" />
 -->




<form action="pay_fee.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&student=<?php echo $_REQUEST['student'];?>#sec" method="get">





<input type="hidden" value="<?php echo $_REQUEST['student']; ?>" name="student" />



   <div>

  <!--  <div class="col-md-3 col-xs-8" style="width: 10em;">

        <div class="SearchNameWidth" style="float: left;width: 9em;">



<?php



  $match;

      if($_REQUEST['session']!=NULL){

        $match=$_REQUEST['session'];

      }else { $match=$_SESSION['current_session']; }

  //echo $match;



?>



             <select name="session"  id="session" class="form-control" >



              <?php



              $WorkAssignList = $m->get("edu_session_config");

              foreach($WorkAssignList as $sessionss)

              { ?>



                 <option <?php if($match==$sessionss['session_id']){echo "selected";} ?> value="<?php echo $sessionss['session_id']; ?>">

                  <?php echo $sessionss['session_year']; ?></option>



          <?php } ?>



          </select>



        </div>





   </div>
 -->

   <div class="col-md-2 col-xs-8" style="width: 10em;">

        <div class="SearchNameWidth" style="float: left;width: 9em;">

  <select name="year" class="form-control">

        <option value="All">All</option>

        <?php

        $match;

        if(!isset($_REQUEST['year'])){

            $match=date("Y");

        }else { $match=$_REQUEST['year']; }

        for($i=2018;$i<2031;$i++){ ?> 

            <option <?php if($match==$i){echo 'selected';}?> value="<?php echo $i; ?>"><?php echo $i; ?></option>

        <?php } ?>  

    </select>


        </div>





   </div>



   <div class="col-md-2 col-xs-4" style="float: left;width: 9em;">

          <input type="submit" value="Search" class="btn-success form-control" style="border-radius:5px;border:none;" >

        </div>



   </div>





</form>



</div>







<?php if(isset($_SESSION['FeeUpdated'])){?>



          <div id="check_std_msg1" class="col-md-12 col-sm-12 col-xs-12" style="margin-bottom:10px;">

                <div class="alert alert-success">

                 <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

                  <strong>Great !</strong> Fee details are updated successfully...

                </div>

          </div>



  <?php unset($_SESSION['FeeUpdated']); }?>



  <?php if(isset($_SESSION['alredy_Added'])){?>



          <div id="toastdelete"><script type="text/javascript"> launch_toastdelete();</script><div id="imgdelete"><b>Warning</b></div><div id="descdelete">Your Record is Already Added..</div></div>



  <?php unset($_SESSION['alredy_Added']); }?>



<div class="panel-body">



<div class="container">

  <div class="row">



   <div class="col-md-12" style="background-color: white;">



    <?php if($WorkAssignListVal[0]['image']!=NULL){ ?>



      <img src="<?php echo DOMAIN;?>Production/students_pics/<?php echo $WorkAssignListVal[0]['image'];?>" id="preview" class="img-thumbnail picture" style="width:100px;height:100px;margin-top: -175px;"   />



   <?php } else { ?>



       <img src="<?php echo DOMAIN;?>Production/images/upload.png" id="preview"  class="img-thumbnail picture" style="width:100px;height:100px;margin-top: -175px;"   />





   <?php } ?>



      <!-- Nav tabs -->

      <div class="card">

                <ul class="nav nav-tabs" role="tablist">



                 <li  class="active" role="presentation"><a href="#Fee<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="home" role="tab" data-toggle="tab">Fee History</a></li>



                 <li role="presentation"><a href="#Family<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Family Fee</a></li>



                    <li role="presentation"><a href="#EditFee<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Edit Student Fee</a></li>



                    <li role="presentation"><a href="#AdvanceChallan<?php echo $WorkAssignListVal[0]['student_id'];?>" aria-controls="profile" role="tab" data-toggle="tab">Creat New Challan</a></li>







                </ul>



                <!-- Tab panes -->

                <div class="tab-content">

<!-- start familly tab -->

<div role="tabpanel" class="tab-pane" id="Family<?php echo $WorkAssignListVal[0]['student_id'];?>">

<?php include('family_fee_info.php'); ?>

</div>

<!-- end family tab -->


<!-- start advance challan tab -->

<div role="tabpanel" class="tab-pane" id="AdvanceChallan<?php echo $WorkAssignListVal[0]['student_id'];?>">



<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data">



       <input type="hidden" value="" class="form-control"  id="validate_status" />



       <input type="hidden" name="action" value="CreateStudentChallan"  />

       <input type="hidden" name="year" value="<?php echo $year; ?>"  />

       <input type="hidden" name="class_id"   value="<?php echo $WorkAssignListVal[0]['class_id']; ?>"  />

       <input type="hidden" name="section_id" value="<?php echo $WorkAssignListVal[0]['section_id']; ?>"  />

       <input type="hidden" name="student_id" value="<?php echo $WorkAssignListVal[0]['student_id']; ?>"  />

       <input type="text" name="standared_fee" value="<?php echo $details[0]['tution_fee']; ?>"  />

       <input type="hidden" name="standared_adm" value="<?php echo $details[0]['admission_fee']; ?>"  />

       <input type="hidden" name="scholorship" value="<?php echo $details2[0]['std_scholarship']; ?>"  />

       <input name="balance" type="hidden" value="<?php echo $student_balance;?>" />





        <h2>Creat Voucher

          <span style="color:red;font-size:14px;">

         (These fee parameters will only include on selected month of voucher)  </span>

       </h2>



<div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

<input type="month" id="month_id_from" name="from_year_month" required class="form-control" min="" value="<?php echo date("Y")."-".date("m");?>">
<span class="form-control-feedback right" aria-hidden="true">From</span>

</div>




<div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

<input type="month" id="month_id_to" onchange="monthCalculate(this.value)" name="to_year_month" required class="form-control" min="" value="<?php echo date("Y")."-".date("m");?>">
<span class="form-control-feedback right" aria-hidden="true">To</span>

</div>



<?php

  $student_balance;

// check if the challan is already created

  $qr = "select * from  eduportal_monthly_challan where branch_id=".$_SESSION['branch'];

  if ($_REQUEST['student']!=NULL) {

      $qr .= " AND student_id=" . $_REQUEST['student']. " ";

  }

  $qr .= " order by challan_id  desc limit 1";

//print_r($qr);

  $student_challan =  $m->query ($qr);


   // print_r($student_challan);



    if(count($student_challan)>0){



      //$std_others_total=getFeeAllOtherFee($_REQUEST['student'],$student_challan[0]['challan_id'],$m);



         $total=$student_challan[0]['total_challan_amt']+$student_challan[0]['arrears']+$std_others_total;

//echo $total."umar";

         //get settlement amount last challan

$sql1 = "SELECT sum(settellment_amount) as settle FROM  eduportal_challan_fee_settlement  WHERE branch_id='$branch' and against_challan_id=".$student_challan[0]['challan_id'];
$LastChallansettellmentAmount = $m->query($sql1);

        $student_balance=$total-($student_challan[0]['received']+$LastChallansettellmentAmount[0]['settle']);
//echo $student_balance."ali";
        //echo $total."--b--".$collected_amount;

    } else {

        $student_balance=$details2[0]['std_outstanding_blc'];

    }


    
$std_id=$_REQUEST['student'];


$query=" select * from eduportal_monthly_challan where student_id='$std_id' order by challan_id desc limit 1 ";

$dueDate = $m->query($query);

if (date("Y-m-d") > $dueDate[0]['challan_duedate'] && $dueDate[0]['challan_duedate']!=NULL) {

      $start_date = strtotime($dueDate[0]['challan_duedate']);     

        if ($dueDate[0]['challan_validity_date'] > date("Y-m-d") ) {
        $end_date = strtotime(date("Y-m-d"));

        } else {
        $end_date = strtotime($dueDate[0]['challan_validity_date']);

        }

    $datediffrencenewchallan =($end_date - $start_date)/60/60/24;

      if($branch_details[0]['fine_type']=="0" || $branch_details[0]['fine_type']==0){
      $student_fine= $branch_details[0]['late_fee_fine'];
      } else {
      $student_fine= ($datediffrencenewchallan * $branch_details[0]['late_fee_fine']);
      }

if ($dueDate[0]['paid_status']==0) {

  if (date("Y-m-d") > $dueDate[0]['challan_duedate'] && $dueDate[0]['challan_duedate']!=NULL) { 
      $student_balance+= $student_fine;
      $onlyFineAmt= $student_fine;

    }

} else {

  $chI=$student_challan[0]['challan_id'];
  $sqq = "SELECT * FROM  eduportal_monthly_challan_details  WHERE branch_id='$branch' and challan_id='$chI' and feetype_id=4";
 
$ft = $m->query($sqq);
$student_balance+= $ft[0]['fee_amount'];
$onlyFineAmt= $ft[0]['fee_amount'];

}
    
    
} // condition if due date grater then


$chI=$student_challan[0]['challan_id'];
$sqq = "SELECT * FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and challan_id='$chI' and feetypeid=4";

$ff = $m->query($sqq);

?>

<input type="hidden" name="previousMonthFine" value="<?php if($onlyFineAmt-$ff[0]['received']!=0){ echo $onlyFineAmt-$ff[0]['received'];}?>">

         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">



            <input type="date" class="form-control" id="duedate" name="duedate" placeholder="Date of Birth" value="<?php echo date("Y-m-d") ?>">

            <span class="form-control-feedback right" aria-hidden="true">Ddate</span>

        </div>


        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">



            <input type="date" class="form-control" id="validity_date" name="validity_date" placeholder="" value="<?php echo date("Y-m-d") ?>">

            <span class="form-control-feedback right" aria-hidden="true">Vdate</span>

        </div>
          


        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">
          <input type="text" onkeyup="create_challan_calculation(this.value)" readonly value="<?php  if($student_balance-$ff[0]['received']!=0){ echo $student_balance-$ff[0]['received'];} ?>"
                  class="form-control" name="outstanding" id="outstanding" placeholder="Old Balance" autocomplete="off" />
          <span class="form-control-feedback right" aria-hidden="true">Baln.</span>
        </div>

  <?php
  

/*printing all the fee types variables*/

 $fee_types1 = $m->get("eduportal_fee_types");

 foreach ($fee_types1 as $type) {

  $FidType=$type['feetype_id'];
  $stdIDid=$WorkAssignListVal[0]['student_id'];
  $query15="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branch' and feetype_id='$FidType' and student_id='$stdIDid' order by challan_id desc limit 1";
  
    $otherRem = $m->query($query15);

//$Trem+=$otherRem[0]['remaining_fee'];

  $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branch' and fee_head_id=".$type['feetype_id'];

        $feeHeads = $m->query($query11);

/*if ($feeHeads[0]['status']) {
  continue;
}*/

?>
    

  <input type="hidden" value="<?php echo $otherRem[0]['remaining_fee'];?>,<?php echo $otherRem[0]['month_id'];?>-<?php echo $otherRem[0]['year'];?>"name="rem<?php echo $type['feetype_id']; ?>" />

  <input type="hidden" name="stdFee" id="stdFee" value="<?php echo $details2[0]['std_tution_fee'] ;?>">
        <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

          <input type="text" class="form-control" <?php if ($type['feetype_id']==1){ echo "readonly";}?> value="<?php 
            if ($type['feetype_id']==1) 
            { echo $details2[0]['std_tution_fee']; 
            } elseif ($type['feetype_id']==2) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==3) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==4) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==5) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==6) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==7) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==8) {
              echo $otherRem[0]['remaining_fee1'];
            } elseif ($type['feetype_id']==9) {
              echo $otherRem[0]['remaining_fee1'];
            } ?>" 
          name="type<?php echo $type['feetype_id']; ?>" id="<?php echo $type['feetype_id'] ;?>" onkeyup="create_challan_calculation(this.value)" placeholder="<?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $type['feetype_name'];} ?>" autocomplete="off" />

          <span class="fa fa-dollar form-control-feedback right" aria-hidden="true"></span>

        </div>

<?php  } ?>


        <!-- <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

          <input type="text" value="<?php  echo $Trem; ?>" class="form-control has-feedback-left" id="bal" name="bal" placeholder="Balance" autocomplete="off" />

          <span class="form-control-feedback left" aria-hidden="true">Bal</span>

        </div> -->

        
         <div class="col-md-3 col-sm-6 col-xs-12 form-group has-feedback">

          <input type="text" value="<?php  echo ($details2[0]['std_tution_fee'])+($student_balance-$ff[0]['received']); ?>" class="form-control has-feedback-left" id="total_amt" name="total_amt" placeholder="Total Challan Fee" autocomplete="off" />

          <span class="form-control-feedback left" aria-hidden="true">Total</span>

        </div>



      <div class="col-md-1 col-sm-6 col-xs-12 form-group">

      <input type="submit" value="Save" class="form-control btn btn-primary" name="submit" />

     </div>



</form>


</div>

<!-- end advance challan tab -->





<!-- start fee edit tab -->

<div role="tabpanel" class="tab-pane" id="EditFee<?php echo $WorkAssignListVal[0]['student_id'];?>">

<?php 




 $show_fee=0;
  if($details2[0]['std_tution_fee']!=""){
    $show_fee=$details2[0]['std_tution_fee'];
  }else {
    $show_fee=$details[0]['tution_fee'];
  }
?>
<input type="hidden" name="class_standared_fee" id="class_standared_fee"  value="<?php echo $details[0]['tution_fee']; ?>" />
<form action="<?php echo DOMAIN;?>Production/parent/InsertMe.php" method="post" enctype="multipart/form-data" class="form-horizontal form-label-left">

<input type="hidden" name="action"  value="UpdateStudnetFee_PayFee">
<input type="hidden" name="student_id"  value="<?php echo $_REQUEST['student']; ?>" />
<input type="hidden" name="fee_id"  value="<?php echo $details[0]['fee_id']; ?>" />
<input type="hidden" name="class_id"  value="<?php echo $WorkAssignListVal[0]['class_id']; ?>" />

<h3 style="text-align:left;margin-top:2%;margin-left:1.3%;"> Fee Parameters (Regular Monthly)  </h3>

        <div class="row">

                   



<div class="col-md-2 col-xs-12" >
<div class="form-group" >

<label>  Montly Fee </label>
<input style="height:40px;padding-left:1%;" type="text" value="<?php echo $show_fee; ?>"  class="form-control field" name="tution_fee" onkeyup="updateScholarship(this.value)" id="tution_fee" />
</div>
</div>   


<div class="col-md-2 col-xs-12" >
<div class="form-group" >

<label>  Student Scholarship </label>
<input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details2[0]['std_scholarship']; ?>"  class="form-control field" name="std_scholarship" id="std_scholarship" />
</div>
</div>             


              

      </div>  <!-- ending row-->  


      <div class="row">

<div class="col-md-3" >
<div class="form-group" >

<input type="submit" class="btn btn-primary" value="Save Record" style="margin-top:10%;"  >

</div>


</div>


</div>   <!--  ending 12 column-->


</form>


</div>
<!-- end fee tab -->



<!-- start Fee tab -->
<div role="tabpanel" class="tab-pane active" id="Fee<?php echo $WorkAssignListVal[0]['student_id'];?>">

<br>
<div style="">
    <table border="1" width="100%" style="font-size:10px;" class="responsive">

        <tr>



                <th width="6%" class="thStyle"> Month / Year </th>

                <th width="4%" class="thStyle"> IssueDate  </th>

                <th width="4%" class="thStyle"> DueDate  </th>

                <th width="4%" class="thStyle"> Arears  </th>

                <th width="4%" class="thStyle"> Current  </th> 

                <th width="4%" class="thStyle"> Fine  </th>    

                <th width="4%" class="thStyle"> Total  </th>

                <th width="5%" class="thStyle"> Action  </th>

                <th width="8%" class="thStyle"> Print/Status  </th>

                <th width="8%" class="thStyle"> Print Receipt  </th>

                <th width="6%" class="thStyle"> Received  </th>

                <th width="6%" class="thStyle"> Fee Settlement  </th>

                <th width="6%" class="thStyle"> Remaining  </th>

                <th width="5%" class="thStyle"> Paid Date </th>

                <th width="5%" class="thStyle"> Received By </th>

                <!-- <th width="8%" class="thStyle"> Action </th> -->

              </tr>

              <?php

                  $m->where("student_id", $WorkAssignListVal[0]['student_id']);

                  // $m->where("session_id", $session2);

                  $m->where("year", $year);

                  $m->orderBy("challan_id","desc");

                  $history = $m->get("eduportal_monthly_challan");

                  $ck=count($history);

                  $counter=0;

                  //print_r($history);

          foreach($history as $details){

              $counter++;

              /*$m->where("Month_Id", $details['month_id']);

              $month=$m->get("eduportal_month_config");*/

              // get challan recevied data

              $sql = "SELECT sum(received) as Treceived, paid_date, paid_time FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and against_challan_id=".$details['challan_id'];
              $receivedChallanData = $m->query($sql);

              //echo $sql;

              $chID=$details['challan_id'];
              $sq = "SELECT receipt_no FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and challan_id='$chID' order by receipt_no desc limit 1";

              $lastRecp = $m->query($sq);

            /*if ($lastRecp[0]['receipt_no']!=NULL) {


            $sql2 = "SELECT sum(remaining) as Tremaining FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and challan_id='$chID' and receipt_no=".$lastRecp[0]['receipt_no'];

            $ChallanRemainingAmount = $m->query($sql2);
            }*/

// get total received amount agaisnt challan id

$sql21 = "SELECT sum(received) as received, sum(remaining) as remng, paid_user_id, paid_by FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and against_challan_id='$chID' ";

$ChallanReceivedAmount = $m->query($sql21);

// get settlement Amount against challan

$sql1 = "SELECT sum(settellment_amount) as settle FROM  eduportal_challan_fee_settlement  WHERE branch_id='$branch' and against_challan_id=".$details['challan_id'];
$settellmentAmount = $m->query($sql1);


// get user name against user id
if ($ChallanReceivedAmount[0]['paid_user_id']!=NULL) {
  $sql22 = "SELECT user_fname FROM  edu_user_config  WHERE branch_id='$branch' and user_id=".$ChallanReceivedAmount[0]['paid_user_id'];
$userName = $m->query($sql22);
}


              // getting students details

              $m->where("student_id", $WorkAssignListVal[0]['student_id']);

              $m->where("status", 0);

              $student=$m->get("edu_student_details");


              $OthersTotal=0+getFeeAllOtherFee($student[0]['student_id'],$details['challan_id'],$m);
            
              $fromMonthYear=explode("-",$details['from_year_month']);
              $toMonthYear=explode("-",$details['to_year_month']);
            
          ?>

          <tr>

            <td><?php
              if ($details['from_year_month']==$details['to_year_month']) {
                echo substr(getMonthName($m,$fromMonthYear[1]), 0, 3)."-".$fromMonthYear[0];
              } else {
                echo substr(getMonthName($m,$fromMonthYear[1]), 0, 3)."-".$fromMonthYear[0]." - ".substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];
              }
             ?></td>


            <td> <?php echo date("d-M-Y",strtotime($details['challan_created']));?></td>
            <td> <?php echo date("d-M-Y",strtotime($details['challan_duedate']));?></td>       
            <td><?php echo $details['arrears'];?></td>
            <td><?php echo $details['total_challan_amt'] ;?></td>
            <td> 

              <?php 
              $student_fine=0;
              $Acutal_student_fine=0;



$mID=$details['from_year_month'];
$yID=$details['year'];
$getFine = "SELECT fee_amount FROM  eduportal_monthly_challan_details  WHERE branch_id='$branch' and challan_id='$chID' and month='$mID' and year='$yID' and feetype_id=4";
//echo $getFine;
$getFineAmount = $m->query($getFine);


$getFineReceived = "SELECT sum(received) as recevd FROM  eduportal_challan_fee_receiving  WHERE branch_id='$branch' and challan_id='$chID' and month='$mID' and year='$yID' and feetypeid=4";
//echo $getFineReceived;
$getFineAmountReceived = $m->query($getFineReceived);
             




if (date("Y-m-d") > $details['challan_duedate'] ) {


$start_date = strtotime($details['challan_duedate']);

if ($details['challan_validity_date'] > date("Y-m-d") ) {
$end_date = strtotime(date("Y-m-d"));

} else {
$end_date = strtotime($details['challan_validity_date']);

}              

$datediffrence =($end_date - $start_date)/60/60/24;


if($branch_details[0]['fine_type']=="0" || $branch_details[0]['fine_type']==0){
$student_fine= $branch_details[0]['late_fee_fine'];
} else {
$student_fine= ($datediffrence * $branch_details[0]['late_fee_fine']);
}


// if row is first

if ($counter==1){

// if row is first and fee is paid then show only collected fine

if($details['paid_status']==1){            

echo $Acutal_student_fine=$getFineAmount[0]['fee_amount'];

}

// if row is first and fee is not paid then calculate fine

else if($details['paid_status']==0){

echo $student_fine;

$Acutal_student_fine=$student_fine;

}

}



} // end due date condition



//else {     

if ($counter!=1){
// if not row is first and then show only collected fine

if($details['paid_status']==1){

if ($getFineAmountReceived[0]['fee_amount']!=NULL) {
echo $Acutal_student_fine=$getFineAmountReceived[0]['fee_amount'];
} 

}

// if row is first and fee is not paid then calculate fine


else if($details['paid_status']==0){

if ($getFineAmount[0]['fee_amount']!=NULL) {
echo $Acutal_student_fine=$getFineAmount[0]['fee_amount'];

} 

}

} // end condition counter != 1

//}

        
              ?>
            </td>
            <td><?php echo $details['arrears']+$details['total_challan_amt']+$Acutal_student_fine;?></td>
            <td>


                 <!-- <?php if($counter==1){ ?> -->

              <!-- <a id="pay" data-toggle="modal" data-target="#payChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:11px;" href="#" class="btn btn-warning">

                  PAY
              </a> -->

              <!-- <a id="settle" data-toggle="modal" data-target="#settle<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:11px;" href="#" class="btn btn-info">

                  Settle
              </a> -->

            <!-- <?php } if($counter==1 && $details['paid_status']==0){ ?>

                            

                 <?php } else if($counter!=1 && $details['paid_status']==0) { ?>

                <a data-toggle="modal" style="padding: 0px 5px; font-size:11px;"  class="btn btn-danger">Not Paid </a>

              <?php } else { ?>


                 <a data-toggle="modal" data-target="#ViewPaidFee<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:11px;" href="#" class="btn btn-success">

                  Paid</i>

                </a>             


               <?php } ?> -->

               

              <div class="btn-group">
                      <button data-toggle="dropdown" style="padding: 2px;" class="btn btn-warning dropdown-toggle btn-sm" type="button" aria-expanded="true">Action <span class="caret"></span>
                      </button>
                      <ul role="menu" class="dropdown-menu">
       
            <?php if($counter==1){ ?>

              <li><a id="pay" style="text-align: left;" data-toggle="modal" data-target="#payChallan<?php echo $details['challan_id'];?>" href="#">

                  PAY
              </a></li>

            <?php if ($details['paid_status']==1 && $ChallanReceivedAmount[0]['remng'] > 0) { ?>

            <li> <a id="settle" style="text-align: left;" data-toggle="modal" data-target="#settle<?php echo $details['challan_id'];?>" href="#">

            Add settlement
            </a></li>

            <?php } ?>
             
            
            <?php } ?>

            <?php if ($settellmentAmount[0]['settle'] > 0) { ?>
              
              <li><a data-toggle="modal" style="text-align: left;" data-target="#Showsettle<?php echo $details['challan_id'];?>" href="#">View Settlement</a></li>
            
            <?php } ?>

            

            <?php if ($ChallanReceivedAmount[0]['received']==NULL && $counter==1) { ?>
              
              <li><a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?challan=<?php echo $details['challan_id'];?>&student=<?php echo $_REQUEST['student'];?>&month=<?php echo $details['from_year_month']."-".$details['to_year_month'];?>&TotalAmount=<?php echo $details['total_challan_amt'];?>&action=DeleteVoucher" style="text-align: left;" onClick="return confirm('Are you sure you want to delete this record');" >Delete</a></li>

            <?php } ?>


            <?php
            //$currentDate = date('d');
             if ($counter==1 && $details['editDueDate']==0  && $details['challan_duedate'] >= date("Y-m-d") ) { ?>
            <li> <a id="dueDate" style="text-align: left;" data-toggle="modal" data-target="#dueDate<?php echo $details['challan_id'];?>" href="#">

            Edit DueDate
            </a></li>
          <?php } ?>
            


                      </ul>
                </div>

<!-- start Show settlement popup code -->


<!-- Modal -->

<div id="Showsettle<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">

<div class="modal-dialog">



<!-- Modal content-->

<div class="modal-content">

<div class="modal-header">

<button type="button" class="close" data-dismiss="modal">&times;</button>

<h4 class="modal-title"> Show Settlement Fee   </h4>

</div>



<div class="modal-body" style="padding: 0px;">


  <table class="table table-striped table-bordered" style="width:96%;margin: 10px;font-size: 12px;">

<thead>
<tr>

<th width="5%">ST#</th>
<th width="15%">Fee</th>
<th width="15%">Settelment</th>
<th width="15%">Balance</th>
<th width="15%">Date/Time</th>
<th width="15%">View</th>
<th width="5%">Action</th>

</tr>
</thead>
<tbody>
<?php 
$s_id=$student[0]['student_id'];
$chlIDs=$details['challan_id'];
//$showSettle = "select sum(amount) as amt, sum(settellment_amount) as settleAmt from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_id' and against_challan_id='$chlIDs' group by settellment_no";
$showSettle="SELECT SUM(amount) as amount, sum(settellment_amount) as settl, settellment_no, student_id, against_challan_id, settellment_date, settellment_time, month FROM eduportal_challan_fee_settlement WHERE  branch_id='$branchID' and student_id='$s_id' and against_challan_id='$chlIDs' group by settellment_no order by settellment_no desc";
//echo $showSettle."====";
$showSettles =  $m->query ($showSettle);
$sno=1;
foreach ($showSettles as $show) { 
$fid=$show['feetypeid'];
$mm=$show['month'];

/*$HeadTotal="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$s_id' and feetype_id='$fid' and month='$mm'";
$HeadTotals = $m->query($HeadTotal);*/

$HeadRecev="SELECT SUM(received) as rcv FROM eduportal_challan_fee_receiving WHERE  branch_id='$branchID' and student_id='$s_id' and against_challan_id='$chlIDs'";
$HeadRecevs = $m->query($HeadRecev);

/*$quer="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id=".$show['feetypeid'];
$feeHeadsN = $m->query($quer);*/

/*if ($show['settellment_amount']==0) {
  continue;
}*/

$m->where("feetype_id", $show['feetypeid']);
$typesN = $m->get("eduportal_fee_types");

$toMonthYear=explode("-",$show['month']);

$TTT +=$show['amount']."<br>";
$sstl+=$show['settl'];
$baals+=($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settl']);
  ?>

  <tr>

<td width="10%"><?php echo $show['settellment_no'];?></td>
<td width="25%"><?php echo  $show['amount'];?></td>
<td><?php echo $show['settl'] ;?></td>
<td width="25%"><?php echo ($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settl']) ;?></td>
<td width="25%" style="font-size:10px;"><?php echo date("M-y", strtotime($show['settellment_date']))." / ".$show['settellment_time'];?></td>
<td>
<!-- <a data-toggle="modal" data-target="#ShowsettleDetails<?php echo $show['settellment_no'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-success">
  View
</a> -->

<a href="show_settlement_details.php?adfkjasdfkljadfldasjfkladsfkldakfjhadfkj&sttleNo=<?php echo $show['settellment_no'];?>&std=<?php echo $student[0]['student_id'];?>&month=<?php echo $show['month'];?>" target="_blank" style="padding: 0px 5px; font-size:14px;"  class="btn btn-success">
  View
</a>
  </td>

<td>
<a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?challanAgainst=<?php echo $show['against_challan_id'];?>&sttleNo=<?php echo $show['settellment_no'];?>&student=<?php echo $show['student_id'];?>&action=DeleteSettlementVoucher" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>
</td>
</tr>

  <?php } ?>

  <!-- <tr style="background-color:lightgray">
    <td style="text-align:center;">Total</td>
    <td><?php echo $TTT;?></td>    
    <td><?php echo $sstl;?></td>
    <td><?php echo $baals;?></td>
    <td></td>
    <td></td>
  </tr> -->



</tbody>

</table> 


</div>


<div class="modal-footer">



<!-- <button type="submit" class="btn btn-primary" name="submit" >Save </button> -->

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

</div>


</div>

</div>

</div>



<!-- end Show settlement popup code -->



<!-- start Show settlement details popup code -->


<!-- Modal -->

<div id="ShowsettleDetails<?php echo $show['settellment_no'];?>" class="modal fade" role="dialog">

<div class="modal-dialog">



<!-- Modal content-->

<div class="modal-content">

<div class="modal-header">

<button type="button" class="close" data-dismiss="modal">&times;</button>

<h4 class="modal-title"> Show Settlement Details</h4>

</div>



<div class="modal-body" style="padding: 0px;">


  <table class="table table-striped table-bordered" style="width:96%;margin: 10px;font-size: 12px;">

<thead>
<tr>

<th width="5%">S.no</th>
<th width="35%">Heads Name</th>
<th width="20%">Fee</th>
<th width="20%">Settelment</th>
<th width="20%">Balance</th>

</tr>
</thead>
<tbody>
<?php 
$s_id=$student[0]['student_id'];
if ($show['settellment_no']!=NULL) {
  $showSettle = "select * from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_id' and settellment_no=".$show['settellment_no'];
$showSettles =  $m->query ($showSettle);
}

$sno=1;
foreach ($showSettles as $show) { 
$fid=$show['feetypeid'];
$mm=$show['month'];

$HeadTotal="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$s_id' and feetype_id='$fid' and month='$mm'";
$HeadTotals = $m->query($HeadTotal);

$HeadRecev="SELECT SUM(received) as rcv FROM eduportal_challan_fee_receiving WHERE  branch_id='$branchID' and student_id='$s_id' and feetypeid='$fid' and month='$mm'";
$HeadRecevs = $m->query($HeadRecev);

$quer="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id=".$show['feetypeid'];
$feeHeadsN = $m->query($quer);

/*if ($show['settellment_amount']==0) {
  continue;
}*/

$m->where("feetype_id", $show['feetypeid']);
$typesN = $m->get("eduportal_fee_types");

$toMonthYear=explode("-",$show['month']);

$TT +=$show['amount'];
$stl+=$show['settellment_amount'];
$bals+=($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']);
  ?>

  <tr>

<td width="10%"><?php echo $sno++;?></td>
<td width="25%"><?php if ($feeHeadsN[0]['fee_head_title']!=NULL){echo $feeHeadsN[0]['fee_head_title'];}else {echo $typesN[0]['feetype_name'];} ?> <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
<td><?php echo $show['amount'] ;?></td>
<td width="25%"><?php echo $show['settellment_amount'];?></td>
<td width="25%"><?php echo ($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']) ;?></td>

</tr>

  <?php } ?>

  <tr style="background-color:lightgray">
    <td colspan="2" style="text-align:center;">Total</td>
    <td><?php echo $TT;?></td>    
    <td><?php echo $stl;?></td>
    <td><?php echo $bals;?></td>   
  
  </tr>



</tbody>

</table> 


</div>


<div class="modal-footer">



<!-- <button type="submit" class="btn btn-primary" name="submit" >Save </button> -->

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

</div>


</div>

</div>

</div>



<!-- end Show settlement Details popup code -->

        <!-- start settlement popup code -->

    <!-- start pay challan popup ========================================================================-->

  <!-- Modal -->

    <div id="settle<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">

    <div class="modal-dialog">



      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title"> Fee Settlement   </h4>

        </div>

            <h4 style="text-align:center;"> <?php echo $student[0]['first_name']." | ".$student[0]['last_name']." | ".$class[0]['Class_Name']."-".$section[0]['section_name']." | ".$student[0]['candidate_roll_no']." | ".$student[0]['ref_no'];?>





        <div class="modal-body" style="padding: 0px;">



       
      </div>



        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">



        <input type="hidden" name="action" value="settelment_amount">

       
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">

        <input type="hidden" name="month" value="<?php echo $details['from_year_month']; ?>">

        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">

        <input type="hidden" name="year" value="<?php echo $details['year']; ?>">      

        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">

      

      <table class="table table-striped table-bordered" style="width:96%;margin: 10px;font-size: 12px;">

      <thead>
      <tr>

       
      <th width="50%">Heads Name</th>
      <!-- <th width="20%">Fee</th> -->
      <th width="20%">Voucher Amount</th>
      <th width="30%">Fee Settelment</th>

      </tr>
      </thead>
      <tbody>
      
         <?php       

         $chID=$details['challan_id'];
         $s_id=$student[0]['student_id'];

         $cMquery="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branch' and challan_id='$chID' and student_id=".$student[0]['student_id'];
          $ChallanMonthYear = $m->query($cMquery);

          $cMquery="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branch' and challan_id='$chID' and student_id=".$student[0]['student_id'];
          $currentChallan = $m->query($cMquery);

          foreach ($currentChallan as $type) {

          $typeID=$type['feetype_id'];
          $year=$type['year'];
          $YearMonth=$type['month'];

          $toMonthYear=explode("-",$type['month']);
           

           $m->where("feetype_id", $type['feetype_id']);
           $typesName = $m->get("eduportal_fee_types");

          $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branch' and fee_head_id=".$type['feetype_id'];
            $feeHeads = $m->query($query11);  
              //$fee;
              //if ($details['status']==0) {
                $Tfee=$type['fee_amount'];
               // echo $Tfee."total<br>";
              //} else {

                 $qr = "select sum(received) as recv from  eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$s_id' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$type['challan_id'];
               $feeHeadRem =  $m->query ($qr);
               $fee=$feeHeadRem[0]['recv'];
//echo $fee."received<br>";
             // }


              // minus fee settlement if any

        $stll = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_id' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$type['challan_id'];
    // echo $stll;
        $settle =  $m->query ($stll);
        $minussettlementFee0=$settle[0]['settle'];
//echo $minussettlementFee0."settlment<br>";
        $fee=$Tfee-$fee-$minussettlementFee0;

            
            ?>
          <?php  if($fee!=0 ){ 

            $totalCurrentMonth+=$fee;

            ?>

             <tr>
          <input type="hidden"  value="<?php echo $fee;?>" name="Total<?php echo $type['month'].$type['feetype_id']; ?>" />          
          <td style="text-align:left;"><?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $typesName[0]['feetype_name'];} ?> <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
          <!-- <td><?php echo $Tfee;?></td> -->
          <td><?php echo $fee;?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text" required  value="<?php// echo $fee;?> "  class="form-control SettlecurrentMonthBalance" onkeyup="settle_net_received(<?php echo $type['feetype_id']; ?>)" name="type<?php echo $type['month'].$type['feetype_id']; ?>" id="currentMonth<?php echo $type['feetype_id']; ?>" /></td>
          </tr>
            <?php } else { ?>

              <input type="hidden"  value="0" id="<?php echo $type['feetype_id5']; ?>" />
          
        <?php } } ?>


         <?php 

        $getFine="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branch' and challan_id='$chID' and student_id='$s_id' and feetype_id=4";
          $getF = $m->query($getFine);

          
        if ($student_fine > 0 && count($getF) == 0) { ?>
          
          <tr>
          <input type="hidden"  value="<?php echo $student_fine;?>" name="currentMonthTotalFine" />          
          <td>Fine <?php echo substr(getMonthName($m,$type['month_id']), 0, 3)."-".$type['year'];?></td>
          <td><?php echo $student_fine;?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text"  value="<?php echo $student_fine;?> "  class="form-control" name="currentMonthReceivedFine" /></td>
          </tr>

        <?php } ?>

          
         
          <tr>
            <td colspan="4" style="background-color: lightgray;padding: 1px;text-align: center;"><b>Arrears</b></td>
          </tr>

<!-- =========================================start previous month balances================================ -->
<?php

$s_ids=$student[0]['student_id'];
$brID=$_SESSION['branch'];

$pre = "select * from eduportal_monthly_challan_arrears where student_id='$s_ids' AND branch_id='$brID' AND against_challan_id='$chID' order by month desc"; 
//echo $pre;
  $previousMonthRemaining = $m->query($pre);


foreach ($previousMonthRemaining as $previousMonthRem) { 

$YearMonth=$previousMonthRem['month'];
$year=$previousMonthRem['year'];
$typeID=$previousMonthRem['feetype_id'];

$toMonthYear=explode("-",$previousMonthRem['month']);

// get total amount

$qrr = "select fee_amount from  eduportal_monthly_challan_details where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetype_id='$typeID' and challan_id=".$previousMonthRem['challan_id'];
//echo $qrr;
$totalFees =  $m->query ($qrr);

$qr = "select sum(received) as rec, amount from  eduportal_challan_fee_receiving where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
$feeHeadRec =  $m->query ($qr);
$fee=$feeHeadRec[0]['rec'];


// minus fee settlement if any

$stl = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
$settle =  $m->query ($stl);
$minussettlementFee=$settle[0]['settle'];


$RemFee=($previousMonthRem['arrears_amount'])-($fee+$minussettlementFee);


if ($RemFee == 0) {
continue;

}

$m->where("feetype_id", $previousMonthRem['feetype_id']);
$type = $m->get("eduportal_fee_types");
$totalSettlementRemaining+=$RemFee;
?>

<tr>
<td><?php echo "<b>".$type[0]['feetype_name']."</b> (". substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0].")";?></td>
<!-- <td><?php echo $totalFees[0]['fee_amount']; ?></td> -->
<td><?php echo $RemFee; ?></td>
<td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text" required value="<?php //echo $RemFee; ?>" onkeyup="settle_net_received(this.value)"  class="form-control SettlecurrentMonthBalance" name="previous<?php echo $type[0]['feetype_id'].$previousMonthRem['month'].$previousMonthRem['year'];?>" id="<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" /></td>


<input type="hidden"  value="<?php echo $RemFee; ?>" name="Totalprevious<?php echo $type[0]['feetype_id'].$previousMonthRem['month'].$previousMonthRem['year'];?>" />
</tr>

<?php } ?>

        <!-- <?php 
        $s_ids=$student[0]['student_id'];
        $brID=$_SESSION['branch'];
      $pre = "select * from eduportal_monthly_challan_details where student_id='$s_ids' AND branch_id='$brID' order by month_id desc"; 
     $previousMonthRemaining = $m->query($pre);

      foreach ($previousMonthRemaining as $previousMonthRem) { 

      $typeID=$previousMonthRem['feetype_id'];
      $year=$previousMonthRem['year'];
      $monthID=$previousMonthRem['month_id'];
      $cid=$previousMonthRem['challan_id'];

        if ($previousMonthRem['month_id']==$details['month_id']) {
           continue;
        }

        if ($previousMonthRem['month_id'] > $details['month_id']) {
           continue;
        }


  $pre = "select * from eduportal_monthly_challan where student_id='$s_ids' AND branch_id='$brID' and challan_id='$cid' group by challan_id order by month_id desc"; 
  $chkStatus = $m->query($pre);

        $RemFee;
        if ($chkStatus[0]['status']==0) {
        $RemFee=$previousMonthRem['fee_amount'];
        
        } else {

        $qr = "select sum(remaining) as rem from  eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$s_ids' and month_id='$monthID' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
        $feeHeadRem =  $m->query ($qr);
        $RemFee=$feeHeadRem[0]['rem'];

        }


        // minus fee settlement if any

        $stl = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_ids' and month_id='$monthID' and year='$year' and feetypeid='$typeID' and challan_id=".$chID;
        $settle =  $m->query ($stl);
        $minussettlementFee=$settle[0]['settle'];

        $RemFee=$RemFee-$minussettlementFee;
        

        if ($RemFee == 0) {
          continue;
        }
        if ($RemFee!=NULL || $RemFee != 0 ) {

        $m->where("feetype_id", $previousMonthRem['feetype_id']);
        $type = $m->get("eduportal_fee_types");

        $totalAmount+=$previousMonthRem['remaining_fee'];


               
        ?>
        
        <tr>
          <td><?php echo "<b>".$type[0]['feetype_name']."</b> (". substr(getMonthName($m,$previousMonthRem['month_id']), 0, 3)."-".$previousMonthRem['year'].")";?></td>
          <td><?php echo $RemFee; ?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text"  value="<?php echo $RemFee; ?>" onkeyup="net_received(this.value)"  class="form-control" name="previous<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" id="<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" /></td>


          <input type="hidden"  value="<?php echo $RemFee; ?>" name="Totalprevious<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" />
        </tr>


    <?php  } 

     }
     ?>
 -->

     <!-- ===================================end previous month balances===================================== -->
        
      <input name="totalAmount" type="hidden"  value="<?php echo $totalAmount1; ?>" />
        <tr style="background-color:#042954; color: white;">
          <td style="color:white;">Total</td>
          <!-- <td style="color:white;"><?php echo $TotalAmountCurrentMonth+$previousMonthTotal;?></td> -->
          <!-- <td style="color:white;" id="totalAmountsSettlement"><?php echo $totalCurrentMonth+$totalSettlementRemaining;?></td> -->
          <td style="color:white;" ><input type="text" style="border: none;background-color:#042954;color: white;" name="" id="totalAmountsSettlement" value="<?php echo $totalCurrentMonth+$totalSettlementRemaining;?>"></td>

          <td style="padding:2px;"><input style="height:23px;padding-left:1%;background-color:#042954;color: white;" autofocus="autofocus" readonly onKeyUp="calculate_amount(this.value);" id="total_settlement_received" type="text" value="<?php //echo $totalCurrentMonth+$totalSettlementRemaining;?>"  required  class="form-control field" name="collected" autocomplete="off" /></td>
        </tr>


        <tr style="background-color:#042954; color: white;">
        <td  style="color:white;">Total Remaining</td>        
          <td colspan="2" style="padding:2px;"><input style="height:23px;padding-left:1%;background-color:#042954;color: white; border: none;text-align: center;" readonly  id="total_remaining_settlement" type="text" value=" <?php //echo $TotalBalanceCurrentMonth+$PreviousMonthBalance ; ?>"  class="form-control field" name="total_remaining_settlement" autocomplete="off" /></td>
        </tr>
      
      </tbody>

      </table> 



<div class="col-md-2" >

<div class="form-group" >

<label style="font-size:11px;"> Settellment No </label>

<input style="padding-left:1%; height:40px;" type="text" readonly  name="receipt_no"  value="<?php echo $settellmentNo; ?>" required  class="form-control field" />

</div>

</div>



<div class="col-md-10" >
<div class="form-group" >

<label style="font-size:11px;">  Settellment Remarks </label>

<input style="height:40px;" autofocus="autofocus" required type="text" class="form-control field" value="" name="settellment_remarks" autocomplete="off" />

</div>

</div>


            <div class="modal-footer">



              <button type="submit" class="btn btn-primary" name="submit" >Save </button>

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





            </div>







                 </form>



          </div>



        </div>

      </div>

    <!-- end pay chalaln popup ========================================================================= -->

        <!-- end settlement popup code -->



        <!-- ============================================= start edit due date poppup============================ -->


  <!-- Modal -->

    <div id="dueDate<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">

    <div class="modal-dialog">



      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title"> Edit Due Date   </h4>

        </div>

        <div class="modal-body" style="padding: 0px;">
       
      </div>



        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data">

        <input type="hidden" name="action" value="edit_due_date">

       
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">

       

<div class="col-md-12" >
<div class="form-group" >

<label>  Due Date </label>

<input required type="date" class="form-control field" value="<?php echo $details['challan_duedate']; ?>" name="due_date" />

</div>

</div>


            <div class="modal-footer">



              <button type="submit" class="btn btn-primary" name="submit" >Save </button>

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





            </div>







                 </form>



          </div>



        </div>

      </div>



        <!-- ================================================== end edit due date popup ============================ -->


    <!-- start pay challan popup ========================================================================-->

  <!-- Modal -->

  <div id="payChallan<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">

    <div class="modal-dialog">



      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title"> Pay Student Fee   </h4>

        </div>


        <div class="modal-body" style="padding: 0px;">



        <h4 style="text-align:center;"> <?php echo $student[0]['first_name']." | ".$student[0]['last_name']." | ".$class[0]['Class_Name']."-".$section[0]['section_name']." | ".$student[0]['candidate_roll_no']." | ".$student[0]['ref_no'];?>



        </h4>


      </div>



        <form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post"  enctype="multipart/form-data" id="PayChallanForm">



        <input type="hidden" name="action" value="PayChallan">

        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">

        <input type="hidden" name="YearMonth" value="<?php echo $details['from_year_month']; ?>">

        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">

        <input type="hidden" name="year" value="<?php echo $details['year']; ?>">

        <input type="hidden" name="std_name" value="<?php echo $student[0]['first_name'];?>">

        <input type="hidden" name="std_no" value="<?php echo $student[0]['cell_no'];?>">

        <input type="hidden" name="fee_recv_sms" value="<?php echo $brid[0]['fee_recv_sms']; ?>">

        <input type="hidden" name="call" value="pay_fee">

        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">

      

      <table class="table table-striped table-bordered" style="width:96%;margin: 10px;font-size: 12px;">

      <thead>
      <tr>


      <th width="40%">Heads Name</th>
      <!-- <th width="20%">Fee</th> -->
      <th width="20%">Voucher Amount</th>
      <th width="20%">Received</th>

      </tr>
      </thead>
      <tbody>
      
         <?php       

         $chID=$details['challan_id'];
         $s_id=$student[0]['student_id'];

         $cMquery="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branch' and challan_id='$chID' and student_id=".$student[0]['student_id'];
          $ChallanMonthYear = $m->query($cMquery);

          $cMquery="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branch' and challan_id='$chID' and student_id=".$student[0]['student_id'];
          $currentChallan = $m->query($cMquery);
//echo $cMquery;
          foreach ($currentChallan as $type) {

          $typeID=$type['feetype_id'];
          $year=$type['year'];
          $YearMonth=$type['month'];

          $toMonthYear=explode("-",$type['month']);
           

           $m->where("feetype_id", $type['feetype_id']);
           $typesName = $m->get("eduportal_fee_types");

          $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branch' and fee_head_id=".$type['feetype_id'];
            $feeHeads = $m->query($query11);  
              //$fee;
              //if ($details['status']==0) {
                $Tfee=$type['fee_amount'];
              //echo $Tfee."total<br>";
              //} else {

                 $qr = "select sum(received) as recv from  eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$s_id' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$type['challan_id'];
               
               $feeHeadRem =  $m->query ($qr);
               $fee=$feeHeadRem[0]['recv'];
              // echo $fee."received<br>";
             // }
//echo $Tfee-$fee."<br>";

              // minus fee settlement if any

        $stll = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$type['challan_id'];
       // echo $stll;
   //  echo $settle[0]['settle']."<br>";
        $settle =  $m->query ($stll);
        $minussettlementFee0=$settle[0]['settle'];

        $fee=$Tfee-$fee-$minussettlementFee0;

          //echo $fee."balance<br>";  
            ?>
          <?php  if($fee!=0 ){ 

            $totalCurrentMonth+=$fee;
            $TotalAmountCurrentMonth+=$Tfee;
            $TotalBalanceCurrentMonth+=$fee;

            ?>

             <tr>
          <input type="hidden"  value="<?php echo $fee;?>" name="Total<?php echo $type['month'].$type['feetype_id']; ?>" />          
          <td><?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $typesName[0]['feetype_name'];} ?> <?php echo getMonthName($m,$toMonthYear[1])."-".$toMonthYear[0];?></td>
          <!-- <td><?php echo $Tfee;?></td> -->
          <td><?php echo $fee;?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" required type="text"  value="<?php //echo $fee;?> "  class="form-control currentMonthBalance" onkeyup="net_received(<?php echo $type['feetype_id']; ?>)" name="type<?php echo $type['month'].$type['feetype_id']; ?>" id="currentMonth<?php echo $type['feetype_id']; ?>" /></td>
          </tr>
            <?php } else { ?>

              <input type="hidden"  value="0" id="<?php echo $type['feetype_id']; ?>" />
          
        <?php } } ?>

        <?php 

        $getFine="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branch' and challan_id='$chID' and student_id='$s_id' and feetype_id=4";
          $getF = $m->query($getFine);

          
        if ($student_fine > 0 && count($getF) == 0) { ?>
          
          <tr>
          <input type="hidden"  value="<?php echo $student_fine;?>" name="currentMonthTotalFine" />          
          <td>Fine <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
          <!-- <td><?php echo $student_fine;?></td> -->
          <td><?php echo $student_fine;?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text"  value="<?php //echo $student_fine;?> "  class="form-control currentMonthBalance" onkeyup="net_received(4)" id="currentMonth4" name="currentMonthReceivedFine" /></td>
          </tr>

        <?php  $AddFine=$student_fine; } ?>
                  
         
          <tr>
            <td colspan="3" style="background-color: lightgray;padding: 1px;text-align: center;"><b>Arrears</b></td>
          </tr>

<!-- =========================================start previous month balances================================ -->


<?php

$s_ids=$student[0]['student_id'];
$brID=$_SESSION['branch'];

$pre = "select * from eduportal_monthly_challan_arrears where student_id='$s_ids' AND branch_id='$brID' AND against_challan_id='$chID' order by month desc"; 
//echo $pre;
  $previousMonthRemaining = $m->query($pre);


foreach ($previousMonthRemaining as $previousMonthRem) { 

$YearMonth=$previousMonthRem['month'];
$year=$previousMonthRem['year'];
$typeID=$previousMonthRem['feetype_id'];

$toMonthYear=explode("-",$previousMonthRem['month']);

// get total amount

$qrr = "select fee_amount from  eduportal_monthly_challan_details where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetype_id='$typeID' and challan_id=".$previousMonthRem['challan_id'];
//echo $qrr;
$totalFees =  $m->query ($qrr);


// for receving 

$qr = "select sum(received) as rec, amount from  eduportal_challan_fee_receiving where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
$feeHeadRec =  $m->query ($qr);
$fee=$feeHeadRec[0]['rec'];


// minus fee settlement if any

$stl = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$brID' and student_id='$s_ids' and month='$YearMonth' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
$settle =  $m->query ($stl);
$minussettlementFee=$settle[0]['settle'];


$RemFee=($previousMonthRem['arrears_amount'])-($fee+$minussettlementFee);


if ($RemFee == 0) {
continue;

}

$m->where("feetype_id", $previousMonthRem['feetype_id']);
$type = $m->get("eduportal_fee_types");

$PreviousMonthBalance+=$RemFee;
  ?>


<tr>
<td><?php echo "<b>".$type[0]['feetype_name']."</b> (". substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0].")";?></td>
<!-- <td><?php echo $totalFees[0]['fee_amount']; ?></td> -->
<td><?php echo $RemFee; ?></td>
<td style="padding:2px;"><input style="height:23px;padding-left:1%;" required type="text"  value="<?php //echo $RemFee; ?>" onkeyup="net_received(this.value)"  class="form-control currentMonthBalance" name="previous<?php echo $type[0]['feetype_id'].$previousMonthRem['month'].$previousMonthRem['year'];?>" id="<?php echo $type[0]['feetype_id'].$previousMonthRem['month'].$previousMonthRem['year'];?>" /></td>


<input type="hidden"  value="<?php echo $RemFee; ?>" name="Totalprevious<?php echo $type[0]['feetype_id'].$previousMonthRem['month'].$previousMonthRem['year'];?>" />
</tr>



<?php } 
 
?>

<!-- 
        <?php 

        $s_ids=$student[0]['student_id'];
        $brID=$_SESSION['branch'];
      $pre = "select * from eduportal_monthly_challan_details where student_id='$s_ids' AND branch_id='$brID' order by month_id desc"; 
     $previousMonthRemaining = $m->query($pre);

      foreach ($previousMonthRemaining as $previousMonthRem) { 

      $typeID=$previousMonthRem['feetype_id'];
      $year=$previousMonthRem['year'];
      $monthID=$previousMonthRem['month_id'];
      $cid=$previousMonthRem['challan_id'];

        if ($previousMonthRem['month_id']==$details['month_id']) {
           continue;
        }

        if ($previousMonthRem['month_id'] > $details['month_id']) {
           continue;
        }


  $pre = "select * from eduportal_monthly_challan where student_id='$s_ids' AND branch_id='$brID' and challan_id='$cid' group by challan_id order by month_id desc"; 
  $chkStatus = $m->query($pre);

        $RemFee;
        if ($chkStatus[0]['status']==0) {
        $RemFee=$previousMonthRem['fee_amount'];
        
        } else {

        $qr = "select sum(remaining) as rem from  eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$s_ids' and month_id='$monthID' and year='$year' and feetypeid='$typeID' and against_challan_id=".$chID;
        $feeHeadRem =  $m->query ($qr);
        $RemFee=$feeHeadRem[0]['rem'];

        }
        
        // minus fee settlement if any

        $stl = "select sum(settellment_amount) as settle from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_ids' and month_id='$monthID' and year='$year' and feetypeid='$typeID' and challan_id=".$chID;
        $settle =  $m->query ($stl);
        $minussettlementFee=$settle[0]['settle'];

        $RemFee=$RemFee-$minussettlementFee;

        if ($RemFee == 0) {
          continue;
        }
        if ($RemFee!=NULL || $RemFee != 0 ) {

        $m->where("feetype_id", $previousMonthRem['feetype_id']);
        $type = $m->get("eduportal_fee_types");

        $totalAmount+=$previousMonthRem['remaining_fee'];


               
        ?>
        
        <tr>
          <td><?php echo "<b>".$type[0]['feetype_name']."</b> (". substr(getMonthName($m,$previousMonthRem['month_id']), 0, 3)."-".$previousMonthRem['year'].")";?></td>
          <td><?php echo $RemFee; ?></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;" type="text"  value="<?php echo $RemFee; ?>" onkeyup="net_received(this.value)"  class="form-control" name="previous<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" id="<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" /></td>


          <input type="hidden"  value="<?php echo $RemFee; ?>" name="Totalprevious<?php echo $type[0]['feetype_id'].$previousMonthRem['month_id'].$previousMonthRem['year'];?>" />
        </tr>


    <?php  } 

     }
     ?>

 -->
     <!-- ===================================end previous month balances===================================== -->
        
         <input type="hidden" id="pMB" name="" value="<?php echo $PreviousMonthBalance ?>">
         <input name="totalAmount" type="hidden"  value="<?php echo $totalAmount1; ?>" />
        <tr style="background-color:#042954; color: white;">
          <td style="color:white;">Total</td>
          <!-- <td style="color:white;"><?php echo $TotalAmountCurrentMonth+$previousMonthTotal;?></td> -->
          <td style="color:white;" ><input type="text" style="border: none;background-color:#042954;color: white;" name="" id="totalAmounts" value="<?php echo $TotalBalanceCurrentMonth+$PreviousMonthBalance+$AddFine;?>"></td>
          <td style="padding:2px;"><input style="height:23px;padding-left:1%;background-color:#042954;color: white;" autofocus="autofocus" readonly onKeyUp="calculate_amount(this.value);" id="total_received" type="text" value=" <?php //echo $TotalBalanceCurrentMonth+$PreviousMonthBalance ; ?>"  required  class="form-control field" name="collected" autocomplete="off" /></td>
        </tr>


        <tr style="background-color:#042954; color: white;">
        <td  style="color:white;">Total Remaining</td>        
          <td colspan="2" style="padding:2px;"><input style="height:23px;padding-left:1%;background-color:#042954;color: white; border: none;text-align: center;" readonly  id="total_remaining" type="text" value=" <?php //echo $TotalBalanceCurrentMonth+$PreviousMonthBalance ; ?>"  class="form-control field" name="total_remaining" autocomplete="off" /></td>
        </tr>

      </tbody>

      </table> 

             


<?php if ($brid[0]['editable_paid_date']==0 && $_SESSION['designation_id']!=12) { ?>


<div class="col-md-4" >

<div class="form-group" >

<label>  Paid Date </label>
<?php

$Date = date("Y-m-d");

$days=' +'.$brid[0]['default_pay_date'].'days';
?>

<input style="padding-left:1%;" type="date" name="paid_date" readonly value="<?php echo date('Y-m-d', strtotime($Date.$days)); ?>" required  class="form-control field" id="paidDate" />

</div>

</div>



<?php } else { ?>


<div class="col-md-4" >

<div class="form-group" >

<label>  Paid Date </label>

<?php

$Date = date("Y-m-d");

$days=' +'.$brid[0]['default_pay_date'].'days';

?>

<input style="padding-left:1%;" type="date"  name="paid_date"  value="<?php echo date('Y-m-d', strtotime($Date.$days)); ?>" required  class="form-control field" id="paidDate" />

</div>

</div>

<?php } ?>

<div class="col-md-4" >

<div class="form-group" >

<label>  Received By </label>

<select name="PiadBy" id="PiadBy" class="form-control" >

<option value="Cash">Cash</option>

<option value="JazzCash">JazzCash</option>

<option value="Easypaisa">Easypaisa</option>

<option value="BankAccount">Bank Account</option>

<option value="UblOmni">Ubl Omni</option>

</select>

</div>

</div>



<div class="col-md-4" >

<div class="form-group" >

<label>  Send Message </label>

<select name="sendmessage" class="form-control">

<option value="Yes">Yes</option>

<option value="No">No</option>

</select>

</div>

</div>


<div class="col-md-2" >

<div class="form-group" >

<label> Receipt No </label>

<input style="padding-left:1%; height:40px;" type="text" readonly  name="receipt_no"  value="<?php echo $reciptNo; ?>" required  class="form-control field" />

</div>

</div>



<div class="col-md-10" >
<div class="form-group" >

<label>  Fee Remarks </label>

<input style="height:40px;" <?php echo $reqFeeRemarks;?> autofocus="autofocus" type="text" class="form-control field" placeholder="<?php echo $brid[0]['prefix_paid_remarks']; ?>" value="" name="fee_remarks" autocomplete="off" />

</div>

</div>


          <script>

function net_received(id) {        


var inputs = document.getElementsByClassName("currentMonthBalance");
var total = 0;

// Loop through all input fields and sum their values
for (var i = 0; i < inputs.length; i++) {
var value = parseInt(inputs[i].value);
if (!isNaN(value)) {
//alert(value);
total += value;
}
}
var PB = document.getElementById('pMB').value;

document.getElementById('total_received').value = total;

var totalAMT = document.getElementById('totalAmounts').value

var totalRevd = document.getElementById('total_received').value   

var fineAMT = document.getElementById('currentMonth4').value

var rem =  totalAMT - totalRevd;

document.getElementById('total_remaining').value = rem;

  }


      function settle_net_received(id) {        
    
    
var inputs = document.getElementsByClassName("SettlecurrentMonthBalance");
var total = 0;

// Loop through all input fields and sum their values
for (var i = 0; i < inputs.length; i++) {
var value = parseInt(inputs[i].value);
if (!isNaN(value)) {
  //alert(value);
total += value;
}
}
document.getElementById('total_settlement_received').value = total;    

var totalAMT = document.getElementById('totalAmountsSettlement').value

var totalRevd = document.getElementById('total_settlement_received').value   

var rem =  totalAMT - totalRevd;

document.getElementById('total_remaining_settlement').value = rem;

      }


          function calculate_amount(str){



            var id = document.getElementById("total").value;

            document.getElementById("balance").value=id-str;





          }



            function net_totals(id) {





        var discount=document.getElementById("discount"+id).value;

        var fine=document.getElementById("fine5"+id).value;

        var total_amt=document.getElementById("totlamt"+id).value;











        var total_amount= (Number(fine) + Number(total_amt)) - Number(discount);



        document.getElementById("totalamt"+id).value=total_amount;









      }

          </script>







            <div class="modal-footer">
              
              <button type="submit" class="btn btn-primary" name="submit">Save </button>

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

            </div>







                 </form>



          </div>



        </div>

      </div>

    <!-- end pay chalaln popup ========================================================================= -->
            </td>
            <td>

              <div class="btn-group">
                      <button data-toggle="dropdown" style="padding:2px;" class="btn btn-warning dropdown-toggle btn-sm" type="button" aria-expanded="true">Print <span class="caret"></span>
                      </button>
                      <ul role="menu" class="dropdown-menu">

                        <li><a href="print_single_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&yearMonth=<?php echo $details['from_year_month'];?>&year=<?php echo $year; ?>&challan=<?php echo $details['challan_id']; ?>" target="_blank">Single Voucher</a></li>

                        <li><a href="print_double_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&yearMonth=<?php echo $details['from_year_month'];?>&year=<?php echo $year; ?>&challan=<?php echo $details['challan_id']; ?>" target="_blank">Double Voucher</a></li>

                        <li><a href="print_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&yearMonth=<?php echo $details['from_year_month'];?>&year=<?php echo $year; ?>&challan=<?php echo $details['challan_id']; ?>" target="_blank">Triple Voucher</a></li>

                         </ul>
                </div>

             




              <?php 

              if($counter==1 && $details['paid_status']==0){

              } elseif ($counter!=1 && $details['paid_status']==0) { ?>

                <a data-toggle="modal" style="padding: 0px 5px; font-size:13px;"  class="btn btn-danger">Not Paid </a>

              <?php } else { ?>


                 <a data-toggle="modal" data-target="#ViewPaidFee<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:13px;" href="#" class="btn btn-success">

                  Paid</i>

                </a>             


               <?php } ?>

            </td>
            <td>

               <?php
              if ($details['paid_status']==1) { ?>
              <a data-toggle="modal" data-target="#PaidChallanInvoice<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-success">
                  Print
              </a>
            <?php } ?>
<!-- ========================================paid challan invoice popup=========================================== -->


 <!-- Modal -->

  <div id="PaidChallanInvoice<?php echo $details['challan_id'];?>" class="modal fade" role="dialog">

    <div class="modal-dialog">



      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title" style="color:#337ab7;text-align: center; "> View Paid Fee </h4>

        </div>





        <div class="modal-body">





        <h4 style="text-align: center;" class="fontpopupheading"> <?php echo $student[0]['first_name'];?> | <?php echo $student[0]['last_name'];?>

          | <?php echo $class[0]['Class_Name']."-".$section[0]['section_name']." | ".$student[0]['candidate_roll_no']." | ".$student[0]['ref_no'];?>



        </h4>





      </div>



        <div class="col-md-12" >



           <table border="1" width="100%" id="paid_table">



              <tr>

                <th width="13%" style="background-color: #337ab7;color: white;"> Rcpt No</th>

                <th width="15%" style="background-color: #337ab7;color: white;"> Fee  </th>

                <th width="15%" style="background-color: #337ab7;color: white;"> Received  </th>

                <!-- <th style="background-color: #337ab7;color: white;"> Settlement  </th> -->

                <th width="12%" style="background-color: #337ab7;color: white;"> Balance  </th>

                <th width="18%" style="background-color: #337ab7;color: white;"> Date/Time  </th>

                <th width="15%" style="background-color: #337ab7;color: white;"> Print  </th>



              </tr>







                <?php


$chID=$details['challan_id'];
$std_ID=$_REQUEST['student'];
$query11="SELECT * FROM eduportal_challan_fee_receiving WHERE  branch_id='$branch' and against_challan_id='$chID' and student_id='$std_ID' group by receipt_no order by challan_received_id desc";

$paidChallans = $m->query($query11);

$reciptCounter=0;
                foreach ($paidChallans as $paidChallan) {
$reciptCounter++;
                  $query11="SELECT sum(amount) as total, sum(received) as received, sum(remaining) as remaining, paid_date, paid_time FROM eduportal_challan_fee_receiving WHERE  branch_id='$branch' /*and challan_id='$chID'*/ and student_id='$std_ID'  and receipt_no=".$paidChallan['receipt_no'];
//echo $query11;
                  $paidChallanDetails = $m->query($query11);

// get settlement amount

                  // $s="SELECT sum(settellment_amount) as st FROM eduportal_challan_fee_settlement WHERE  branch_id='$branch' and challan_id='$chID' ";

                  // $stlamt = $m->query($s);

                  ?>

                <tr style="text-align:center;">

                  <td><?php echo $paidChallan['receipt_no']; ?></td>

                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $paidChallanDetails[0]['total'];?></td>

                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $paidChallanDetails[0]['received'];?></td>

                  <!-- <td style="color: black;text-align: left;padding: 1%;"><?php echo $stlamt[0]['st'];?></td> -->

                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $paidChallanDetails[0]['remaining']/*-$stlamt[0]['st']*/;?></td>

                  <td style="color: black;text-align: left;padding: 1%;font-size: 10px;"><?php echo date("d-m-y", strtotime($paidChallanDetails[0]['paid_date']))." / ".$paidChallanDetails[0]['paid_time'];?></td>

                  <td style="color: black;text-align: left;padding: 1%;">

                  <div class="btn-group">
                  <button data-toggle="dropdown" style="padding:2px;" class="btn btn-warning dropdown-toggle btn-sm" type="button" aria-expanded="true">Print <span class="caret"></span>
                  </button>
                  <ul role="menu" class="dropdown-menu">

                  <li><a href="print_single_voucher_paid.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;receipt=<?php echo $paidChallan['receipt_no'];?>&student_id=<?php echo $paidChallan['student_id'];?>&month_id=<?php echo $paidChallan['month'];?>&year=<?php echo $paidChallan['year'];?>&challan=<?php echo $paidChallan['challan_id'];?>&againstchallan=<?php echo $paidChallan['against_challan_id'];?>" target="_blank">
                     Single Receipt
                   </a></li>

                  <li><a href="print_double_voucher_paid.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;receipt=<?php echo $paidChallan['receipt_no'];?>&student_id=<?php echo $paidChallan['student_id'];?>&month_id=<?php echo $paidChallan['month'];?>&year=<?php echo $paidChallan['year'];?>&challan=<?php echo $paidChallan['challan_id'];?>&againstchallan=<?php echo $paidChallan['against_challan_id'];?>" target="_blank">Double Receipt</a></li>


                  </ul>
                  </div>
                    
                    

                   <?php //if ($reciptCounter==1) { ?>                     
                   
                   <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?challanRecvd=<?php echo $paidChallan['challan_received_id'];?>&challan=<?php echo $paidChallan['against_challan_id'];?>&student=<?php echo $paidChallan['student_id'];?>&receipt_no=<?php echo $paidChallan['receipt_no'];?>&action=DeleteReceivedVoucher" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

                 <?php //} ?>

                  </td>

                </tr>



              <?php } ?>




             </table>







        </div>



<div style="color: white;">.</div>



            <div class="modal-footer">



              <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>





            </div>











          </div>



        </div>

      </div>



      <!-- ending -->


<!-- ========================================end paid chalaln popup=============================================== -->

<!-- $details['received'] -->
            </td>
            <td><?php echo $ChallanReceivedAmount[0]['received'];?></td>
            <td><?php echo $settellmentAmount[0]['settle'];?></td>
            <td><?php echo ($details['arrears']+$details['total_challan_amt']+$Acutal_student_fine)-($ChallanReceivedAmount[0]['received']+$settellmentAmount[0]['settle'])?></td>
            <td><?php  if($receivedChallanData[0]['paid_date']!=NULL){echo date("d-m-Y", strtotime($receivedChallanData[0]['paid_date']))."<br>".$receivedChallanData[0]['paid_time'];}?></td>
            <td><?php if ($receivedChallanData[0]['paid_date']!=NULL) {
              echo $userName[0]['user_fname']; } ?></td>
            <!-- <td>
              
              <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?challan=<?php echo $details['challan_id'];?>&student=<?php echo $_REQUEST['student'];?>&action=DeleteVoucher" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>

            </td> -->


          </tr>
<?php } ?>
    </table>
</div>


          </div>
<!-- end Fee tab -->


          </div>



        </div>

      </div>



      




</div>





                    </div>









                </div>





      </div>



       </div> <!-- col 9 -->

  </div>

</div>  <!-- container -->





    <br><br>



<div class="clearfix"></div>

</div>

</div>



    </div>



  </div>

  <div class="clearfix"></div>

</section>



          </div>

        </div>



            </div>

          </div>

        </div>

        <!-- /page content -->



        <script type="text/javascript">





function copyData()

{

  var n1 = document.getElementById('installment');

  var n2 = document.getElementById('firstInstallment');

  n2.value = n1.value;

 

calculate_totalAmount(22,1);

}



function copyDueDate()

{

  

  var d1 = document.getElementById('duedate');

  var d2 = document.getElementById('firstInstallmentDuedate');

  d2.value = d1.value;





}





   



function calculate_totalAmount(val,id){

 //alert(val+"==="+id);

 var firstInstall=document.getElementById("firstInstallment").value;

 //alert(firstInstall);

 var transport=document.getElementById("transport_fee1").value;

 var misc=document.getElementById("installment_std_misc_fee1").value;

 var arrear=document.getElementById("installment_outstanding1").value;

 var total=0;

 for(i=1;i<=8;i++){



  var sum=document.getElementById("fee_type"+i).value;



  total = parseInt(total) + parseInt(sum);



 }

 

   var totalPayable= Number(total) + Number(firstInstall) + Number(transport) + Number(misc) + Number(arrear);



  document.getElementById("total_payable").value=totalPayable;





}







</script>



  <?php include('RootMe/js_linksscript.php');?>





  <link rel="stylesheet" href="colorbox.css" />

  <link rel="stylesheet" href="https://apps.eduportal-pk.com/EduPortal/Production/css/style11.css" />



<script src="jquery.colorbox.js"></script>



 <script>



$(document).ready(function(){



$(".iframePupop").colorbox({iframe:true, width:"80%", height:"85%"});



});





function create_challan_calculation(id) {        
              
        
        var type1=document.getElementById("1").value;
        var type2=document.getElementById("2").value;
        var type3=document.getElementById("3").value;
        var type4=document.getElementById("4").value;
        var type5=document.getElementById("5").value;
        var type6=document.getElementById("6").value;
        var type7=document.getElementById("7").value;
        var type8=document.getElementById("8").value;
       // var type9=document.getElementById("9").value;
        var bal=document.getElementById("outstanding").value;
       
        
        var total_amount= (Number(type1) + Number(type2) + Number(type3) + Number(type4) + Number(type5) + Number(type6) + Number(type7) + Number(type8) + Number(bal) /*+ Number(type9) */ );
   
        document.getElementById("total_amt").value=total_amount;
        
      }

        document.addEventListener("DOMContentLoaded", function() {
    // Focus on the input field when the page loads
    document.getElementById("currentMonth<?php echo $type['feetype_id']; ?>").focus();
  });


 
</script>


  </body>

</html>

