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


<div id="myIDID" style="">

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


              <tr>  

                <th width="4%" class="thStyle"> Month  </th>
                <th width="4%" class="thStyle"> DueDate  </th>
                <th width="6%" class="thStyle"> Monthly Fee  </th>
                <th width="4%" class="thStyle"> Balance  </th>
                <th width="4%" class="thStyle"> Fine  </th>
                <th width="4%" class="thStyle"> OtherFunds  </th>
                <th width="4%" class="thStyle"> Total  </th>
                <th width="6%" class="thStyle"> Print Voucher  </th>
                <th width="8%" class="thStyle"> Fee Status  </th>
                <th width="6%" class="thStyle"> Paid Amount </th>
                <th width="4%" class="thStyle"> Remaining  </th>
                <th width="5%" class="thStyle"> Paid Date </th>
                <th width="7%" class="thStyle"> Action </th>
                
              </tr>

<?php 


  $m->where("student_id", $_REQUEST['student_id']);
  $m->where("session_id", $_REQUEST['session_id']);
  $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");


    $m->where("user_id", $details['paid_fee_user_id']);
    $PaidFeeUser=$m->get("edu_user_config");

    $m->where("user_id", $details['paid_again_user_id']);
    $AgainPaidFeeUser=$m->get("edu_user_config");


    $m->where("challan_id", $details['challan_id']);
    $m->where("month_id", $details['month_id']);
    $m->where("student_id", $_REQUEST['student_id']);
    $m->where("branch_id", $_SESSION['branch']);
    $againData=$m->get("eduportal_again_paid_challan");

//print_r($againData);
     // getting students details 

    $m->where("student_id", $_REQUEST['student_id']);
    $m->where("status", 0);
    $student=$m->get("edu_student_details");

   
    $OthersTotal=0+getFeeAllOtherFee($student[0]['student_id'],$details['challan_id'],$m);

    $totalAmount= $details['tutionfee']+$details['transportfee']+$details['balance']+$details['misc_fee']+$OthersTotal; 

    //echo $details['transportfee']+$details['balance']+$details['misc_fee'];

    $start_date = strtotime($details['challan_duedate']); 
    $end_date = strtotime(date("Y-m-d"));
    $datediffrence =($end_date - $start_date)/60/60/24;

    // calculating student discount
    $discount_fee=($details['disc_amount']/$details['tutionfee'])*100;
      

    $totalAmount1=$totalAmount-$details['disc_amount']; 
?>            
          <tr>  

            <td> <?php echo $month[0]['Month_Name'];?> </td>
            <td> <?php echo date("d-M-Y",strtotime($details['challan_duedate']));?> </td>
            <td> <?php echo $details['tutionfee'];?> </td>
            <td> <?php echo 0+$details['balance'];?> </td>
            
          <td> <?php 

    $student_fine=0;
    $actual_fine=0;



  
   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']);
   }

$fine_date;

          if ($brid[0]['default_pay_date']=='-1') {
            
            $fine_date=date('Y-m-d', strtotime('-1 day'));

          } else {

            $fine_date=date("Y-m-d");
          }
          
  //if(date("Y-m-d")>$details['challan_duedate'] && $details['paid_status']==1){

// 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 $details['collected_fine'];
             $actual_fine=$details['collected_fine'];
           
          } 
          
         
        // if row is first and fee is not paid then calculate fine
          else if($fine_date>$details['challan_duedate'] && $details['paid_status']==0){
            echo $student_fine; 
            $actual_fine=$student_fine;
          }
      
    } 
// if not row is first and then show only collected fine
    else {
          $collectedORnot;
          if ($details['collected_fine']!="") {
            
            echo $collectedORnot=$details['collected_fine'];
          } else {
            echo $collectedORnot=$student_fine; 
          }
         
         $actual_fine=$collectedORnot;
    }
    


    $totalAmount1+=$actual_fine;

        ?> 

        </td>

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


        <a data-toggle="modal" data-target="#otherFee<?php echo $_REQUEST['student_id'];?>" style="padding: 0px 4px; font-size:14px;"  class="btn btn-warning">
          <?php echo $OthersTotal;?>  
        </a> 


      <!-- Modal -->
      <div id="otherFee<?php echo $_REQUEST['student_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content" style="width: 900px;margin-left: -25%;">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title"> Other Fee Parameters  </h4>
            </div>


            <div class="modal-body">



              <p> <?php echo $student[0]['first_name'];?>  <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo getClassName($m,$_GET['class_id']);?>)

              </p>


            </div>


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

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


              <tr>  

                <th class="thStyle" style="text-align: center;padding:1%;"> Fee Type  </th>
                <th class="thStyle" style="text-align: center;padding:1%;"> Amount  </th>
              
              </tr>
<?php 

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

if(count($fee_types)<=0){
  echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

}

 foreach ($fee_types as $type) {

  $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
  if($fee==NULL){
    continue;
  }

?>            
              <tr>  

                <td> <?php echo $type['feetype_name'];?> </td> 
                <td> <?php echo $fee;?> </td> 
                
              </tr>

<?php   } ?>

             </table>

          </div>

          <br><br>


            <div class="modal-footer">

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


            </div>

          </div>

        </div>
      </div>

      <!-- ending modal -->

               </td>

              <td style="text-align:center;"> <?php echo $totalAmount1 ; ?>   </td>
             

                <td>

                <div class="btn-group">
                      <button data-toggle="dropdown" 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">
       <?php 

    $page;

    if($brid[0]['triple_single_voucher']!=NULL){
      $page=$brid[0]['triple_single_voucher'];
    }else{
      $page="print_voucher.php";  
    }

    ?>
     
   
            <li><a href="print_single_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $_REQUEST['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Single Voucher</a></li>

            <li><a href="print_double_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $_REQUEST['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Double Voucher</a></li>

            <li><a href="<?php echo $page;?>?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $_REQUEST['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>" target="_blank">Triple Voucher</a></li>

            <!-- <li><a href="print_single_family_profile_voucher.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $WorkAssignListVal[0]['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>&familyCode=<?php echo $WorkAssignListVal[0]['cell_no'];?>&familyName=<?php echo $WorkAssignListVal[0]['last_name'];?>" target="_blank">Single Family Voucher</a></li> -->

            <li><a href="print_family_profile_voucher_db.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;student_id=<?php echo $_REQUEST['student_id'];?>&month=<?php echo $month[0]['Month_Name'];?>&month_id=<?php echo $month[0]['Month_Id'];?>&session=<?php echo $session1; ?>&familyCode=<?php echo $WorkAssignListVal[0]['cell_no'];?>&familyName=<?php echo $WorkAssignListVal[0]['last_name'];?>" target="_blank">Double Family Voucher</a></li>

           
                      </ul>
                </div>
                &nbsp;

                

               
      <!-- Modal -->
      <div id="EditChallan<?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 Fee Challan   </h4>
            </div>


            <div class="modal-body">

<?php 

$sql_fee = " select * from  eduportal_class_fee_details where branch_id=".$_SESSION['branch']." AND class_id=".$_REQUEST['class_id'];
$class_fee = $m->query($sql_fee);


// now checking if the fee is not paid then put class standard dues on parameters...

?>

              <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo $class[0]['Class_Name'];?>)

              </h4>


            </div>

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

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

          <input type="hidden" name="action" value="EditChallan">
          <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
          <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
          <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
          <input type="hidden" name="session" value="<?php echo $session1; ?>">
          <input type="hidden" name="call" value="pay_fee">
          <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">



                <div class="form-group" >
                        
                        <label>  Monthly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" name="tutionfee" id="tutionfee" />
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="transportfee" id="transportfee" />
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?>  </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee']; ?> "  class="form-control field" name="misc_fee" id="misc_fee" />
                      </div>
                  </div>
          
          
            <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                                   
                  <?php
                  $Date = date("Y-m-d");
                  
                  ?>

      <input style="height:40px;padding-left:1%;" type="date" name="challan_duedate"  value="<?php echo $details['challan_duedate']; ?>" required  class="form-control field" id="paidDate" />

                    </div>
              </div>



                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>" name="balance"  class="form-control field" />
                      </div>
                  </div>


              <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fine  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine" 
                      value="<?php echo $actual_fine;?>"  class="form-control field" name="fine" />
                  </div>
              </div>




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

                           <div class="form-group ">

                        <label class="required">Fee Discount</label>
                            <select name="disc_type" id="disc_type" class="form-control">

              <!-- <option <?php if($details['disc_type']=="Fixed"){echo 'selected';}?> 
              value="Fixed">Fixed</option> -->
              <option <?php if($details['disc_type']=="Percentage"){echo 'selected';}?> 
              value="Percentage">Percentage</option>


                            </select>
                        </div>

                </div> 
        

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

                  <label class="required"> Discount (%)</label>
                      <input name="disc_amount"  
                      value="<?php echo $discount_fee; ?>" type="text" class="form-control"  
                      >      
                  </div>
              </div>   






  <table>     
<?php 

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

if(count($fee_types)<=0){
  echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

}

 foreach ($fee_types as $type) {

  $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
  if($fee==NULL){
    
  }

?>            
              <tr>  

                

                <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label> <?php echo $type['feetype_name'];?></label>
                     

   <input  style="height:40px;padding-left:1%;" type="text" class="form-control" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off" />



                  </div>
              </div>



               
                
              </tr>

<?php   } ?>
             
</table>

            <div class="modal-footer col-md-12 col-xs-12">

              <button type="submit" class="btn btn-primary" name="submit" >Update Fee </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>

                 
                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->

      <!-- Modal -->
      <div id="AddCommitment<?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"> Add Commitment   </h4>
            </div>


            <div class="modal-body">

<?php 

$sql_fee = " select * from  eduportal_class_fee_details where branch_id=".$_SESSION['branch']." AND class_id=".$_REQUEST['class_id'];
$class_fee = $m->query($sql_fee);


// now checking if the fee is not paid then put class standard dues on parameters...

?>

              <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo $class[0]['Class_Name'];?>)

              </h4>


            </div>

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

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

          <input type="hidden" name="action" value="AddCommitment">
          <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
          <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
          <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
          <input type="hidden" name="session" value="<?php echo $session1; ?>">
          <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">


          
          
            <div class="col-md-12" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                                   
                  <?php
                  $Date = date("Y-m-d");
                  
                  ?>

      <input style="height:40px;padding-left:1%;" type="date" name="commitment_date"  value="<?php echo $details['commitment_date']; ?>" required  class="form-control" id="" />

                    </div>
              </div>



                 <div class="col-md-12" >
                      <div class="form-group" >
                        
                        <label>  Commitment </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['commitment']; ?>" name="commitment"  class="form-control" />
                      </div>
                  </div>   
  

            <div class="modal-footer col-md-12 col-xs-12">

              <button type="submit" class="btn btn-primary" name="submit" >Add Commitment </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>

            </div>    
                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->
      
      <!-- Eid Paid Challan Modal -->
      <div id="EditPaidChallan<?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 Paid Fee  </h4>
            </div>


            <div class="modal-body">

<?php 



$sql_fee = " select * from  eduportal_class_fee_details where branch_id=".$_SESSION['branch']." AND class_id=".$_REQUEST['class_id'];
$class_fee = $m->query($sql_fee);


// now checking if the fee is not paid then put class standard dues on parameters...

?>

              <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
                (<?php echo $class[0]['Class_Name'];?>)

              </h4>


            </div>


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

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

          if(count($fee_types)<=0){
            echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

          }

           foreach ($fee_types as $type) {

            $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
            if($fee==NULL){
              
            }

          ?>            
             
                  <div class="col-md-4" >
                    <div class="form-group" >
                      
                      <label> <?php echo $type['feetype_name']; ?>   </label>
                        <input style="height:40px;padding-left:1%;" type="text" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off"  class="form-control field" name="fine" />
                    </div>
                </div>  




          <?php   } ?>

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



          <input type="hidden" name="action" value="EditPaidChallan">
          <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
          <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
          <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
          <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
          <input type="hidden" name="call" value="profile">
          <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">



                      <div class="form-group" >
                        
                        <label>  Montly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" name="tutionfee" id="tutionfee" />
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="transportfee" id="transportfee" />
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?>  </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee']; ?> "  class="form-control field" name="misc_fee" id="misc_fee" />
                      </div>
                  </div>
          
          
            <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Due Date </label>
                                   
                  <?php
                  $Date = date("Y-m-d");
                  $dd=date('Y-m-d', strtotime($details['paying_date']));
                  ?>

      <input style="height:40px;padding-left:1%;" type="date" name="challan_duedate"  value="<?php echo $details['challan_duedate']; ?>" required  class="form-control field" id="paidDate" />

                    </div>
              </div>


              <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                                   
        
                            <input style="height:40px;padding-left:1%;" type="date" name="paid_date"  value="<?php echo $dd; ?>" required  class="form-control field" id="paidDate" />
                          </div>
                    </div>



                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>" name="balance"  class="form-control field" />
                      </div>
                  </div>




              <div class="col-md-4" >
                  <div class="form-group" >
                    
                    <label>  Fine  </label>
                      <input style="height:40px;padding-left:1%;" type="text" id="fine"
                       value="<?php echo $actual_fine; ?>"  class="form-control field" name="fine" />
                  </div>
              </div>



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

                  <label class="required">Fee Discount</label>
                      <input name="disc_amount"  
                      value="<?php echo $details['disc_amount']; ?>" type="text" class="form-control"  
                      >      
                  </div>
              </div>   


                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Total Fee </label>
                              <input type="hidden" name="totalAmount" value="<?php echo $totalAmount1+$others_fee; ?>">
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $totalAmount1; ?>"  class="form-control field" readonly/>
                          </div>
                    </div>




                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Fee </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['collected_amount']; ?>"  class="form-control field" name="total_paid" />
                          </div>
                </div>

                <? if ($details['paid_again_amount']!=NULL) { ?>
                  
               
                <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Again Date </label>
                                   
        
                            <input style="height:40px;padding-left:1%;" type="date" name="paid_again_date"  value="<?php echo $details['paid_again_date']; ?>" required  class="form-control field" id="paidDate" />
                          </div>
                </div>

                <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid Again Fee </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['paid_again_amount']; ?>"  class="form-control field" name="paid_again_amount" />
                          </div>
                </div>

              <?php } ?>


              <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Remaining </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo ($totalAmount1-$details['collected_amount']-$details['collected_fine']-$details['paid_again_amount']); ?>"  class="form-control field" name="" readonly />
                          </div>
                    </div>

            <div class="modal-footer">

              <button type="submit" class="btn btn-primary" name="submit" >Update Fee </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

        </div>
      </div>

      <!-- ending -->
      

          </td>


      <!-- these are the hidden fields... -->

  <input  type="hidden"  value="<?php echo $details['month_id']; ?>" id="month"/>
  <input  type="hidden"  value="<?php echo $month[0]['Month_Name']; ?>" id="month_name"/>

  <input  type="hidden"  value="<?php echo date("Y-m-d"); ?>" id="date"/>
  

  <input  type="hidden"  value="<?php echo $totalAmount+$actual_fine-$details['disc_amount']; ?>" id="totalAmount"/>
  <input  type="hidden"  value="<?php echo $details['student_id']; ?>" id="student"/>
  <input  type="hidden"  value="0" id="fine"/>
  <input  type="hidden"  value="<?php echo $details['challan_id']; ?>" id="challan_id"/>
  <input  type="hidden"  value="<?php echo $brid[0]['fee_recv_sms']; ?>"  id="fee_recv_sms"/>
  <input  type="hidden"  value="<?php echo $brid[0]['double_confirmation_sms_to_principal']; ?>" id="double_confirmation_sms_to_principal"/>
  <input  type="hidden"  value="<?php echo $student[0]['first_name']; ?>"  id="std_name"/>
  <input  type="hidden"  value="<?php echo $student[0]['cell_no']; ?>"  id="std_no"/> 
  <input  type="hidden"  value="<?php echo $brid[0]['Owner_no']; ?>" id="Owner_no"/>
   

            <td>

              <?php if($counter==1 && $details['paid_again_date']==NULL && $details['paid_status']==1  ){ ?> 

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

                  Pay Again
                  
              </a>
            <?php } ?>
                
             <?php if($counter==1 && $details['paid_status']==0){ ?>    

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

                  PAY
                  
              </a> 

              <a id="paynow" onClick="PayFullFee();" style="padding: 0px 5px; font-size:14px;"  class="btn btn-danger">

                  Pay Full 

              </a>

               <a id="fullpaid<?php echo $count;?>" style="padding: 0px 5px; font-size:14px;display:none;"  class="btn btn-success">

                  Fully Paid <i class="fa fa-check" aria-hidden="true"></i><i class="fa fa-check" aria-hidden="true"></i>

               </a>

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


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

              <?php }else{ ?>   

                <!-- <a data-toggle="modal" style="padding: 0px 5px; font-size:14px;"  class="btn btn-success">Paid </a> --> 

                
                   
                 <a data-toggle="modal" data-target="#ViewPaidFee<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-success">
                  Paid&nbsp;&nbsp;<i class="fa fa-search" aria-hidden="true"></i>
                </a>
                </a>  
                  
               <?php } ?>   
             
 <!-- Modal -->
  <div id="ViewPaidFee<?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 style="background-color: #337ab7;color: white;"> Particular</th>
                <th style="background-color: #337ab7;color: white;"> Amount  </th>
                
              </tr>     


                
                <?php 
                $fee_types = $m->get("eduportal_fee_types");

                foreach ($fee_types as $type) { 

                  $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
                  ?>
                <tr> 
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $type['feetype_name'];?></td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $fee;?></td>
                </tr>

              <?php } ?>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;"><?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?> Charges</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['misc_fee'];?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Tuition Fee</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['tutionfee'];?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Transport Fee</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['transportfee'];?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Prev.Balance</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['balance'];?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Fine</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $actual_fine;?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Fee Discount</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['disc_amount'];?></td>
              </tr>

               <tr style="background-color: #337ab7;"> 
                  <td style="color: white;text-align: left;padding: 1%;">Total Payable</td>
                  <td style="color: white;text-align: left;padding: 1%;"><?php echo $totalAmount1+$others_fee; ?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Due Date</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo date('d-M-Y', strtotime($details['challan_duedate'])); ?></td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Paid Fee</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['collected_amount']+$actual_fine; ?> (<?php if ($details['paying_date']!=NULL) { echo date('d-M-Y', strtotime($details['paying_date'])); } ?> <?php echo $details['paying_time'];?>) By: <?php echo $PaidFeeUser[0]['user_fname'] ?> </td>
              </tr>

              <?php if($details['paid_again_date']!=NULL) { ?>
              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Paid Again</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $details['paid_again_amount']; ?> (<?php if ($details['paid_again_date']!=NULL) { echo date('d-M-Y', strtotime($details['paid_again_date'])); } ?> <?php echo $details['paid_again_time'];?>) By: <?php echo $AgainPaidFeeUser[0]['user_fname'] ?></td>
              </tr>

            <?php } ?> 

              <tr style="background-color: #337ab7;">  
                  <td style="color: white;text-align: left;padding: 1%;">Total Paid</td>
                  <td style="color: white;text-align: left;padding: 1%;"><?php echo $details['collected_amount']+$actual_fine+$details['paid_again_amount']; ?> </td>
              </tr>

              <tr> 
                  <td style="color: black;text-align: left;padding: 1%;">Remainings</td>
                  <td style="color: black;text-align: left;padding: 1%;"><?php echo $totalAmount1+$others_fee-$details['collected_amount']-$details['paid_again_amount']-$actual_fine; ?></td>
              </tr>
                                   
           
            
             </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 -->

  <!-- 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">

        <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
          (<?php echo $class[0]['Class_Name'];?>)

        </h4>


      </div>


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

  

           
          <?php 

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

          if(count($fee_types)<=0){
            echo "<tr> <td colspan='10' style='color:red;text-align:center;'> No record found ! </td> </tr> ";

          }

           foreach ($fee_types as $type) {

            $fee=getFeeOfOtherParameter($student[0]['student_id'],$details['challan_id'],$type['feetype_id'],$m);
            if($fee==NULL){
              
            }

          ?>            
             
                  <div class="col-md-4" >
                    <div class="form-group" >
                      
                      <label>  <?php echo $type['feetype_name']; ?>  </label>
                        <input style="height:40px;padding-left:1%;" readonly type="text" name="type<?php echo $type['feetype_id']; ?>" id="proc_fee" value="<?php echo $fee;?>"  placeholder="<?php echo $type['feetype_name']; ?>" autocomplete="off"  class="form-control field" name="fine" />
                    </div>
                </div>  

          <?php   } ?>


        <input type="hidden" name="action" value="PayChallan">
        <input  type="hidden" name="month_name" value="<?php echo $month[0]['Month_Name']; ?>"/>
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
        <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
        <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
        <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']; ?>">
        <!-- fee details  -->
        <input type="hidden" name="adm" value="<?php echo $adm_fee; ?>">
        <input type="hidden" name="paper" value="<?php echo $paper; ?>">
        <input type="hidden" name="lab" value="<?php echo $lab; ?>">
        <input type="hidden" name="lib" value="<?php echo $library; ?>">
        <input type="hidden" name="other" value="<?php echo $oth_fee; ?>">


             <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?> Charges </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['misc_fee'];?>"  class="form-control field" name="misc" id="misc" readonly/>
                      </div>
                  </div>


                <br>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Montly Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['tutionfee']; ?>"  class="form-control field" id="lname" readonly/>
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Transport Fee </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['transportfee']; ?> "  class="form-control field" name="" id="lname" readonly/>
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Prev.Balance </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $details['balance']; ?>"  class="form-control field" readonly/>
                      </div>
                  </div>



              <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Fine </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $actual_fine;?>"  class="form-control field" id="fine5<?php echo $details['challan_id'];?>" 
                        onkeyup="net_totals(<?php echo $details['challan_id'];?>)" name="fine"/>
                      </div>
                </div>


      

               <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Discount </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $details['disc_amount'];?>"  class="form-control field" id="discount<?php echo $details['challan_id'];?>" onkeyup="net_totals(<?php echo $details['challan_id'];?>)" name="disc_amount"/>
                      </div>
                </div>

                <input id="totlamt<?php echo $details['challan_id'];?>" type="hidden" name="" value="<?php echo $totalAmount;?>">
                
                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Total </label>
                              
                              <input style="height:40px;padding-left:1%;" name="totalAmount" type="text"  value="<?php echo $totalAmount1; ?>"  class="form-control field" id="totalamt<?php echo $details['challan_id'];?>" readonly/>
                          </div>
                    </div>


                 <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="height:40px;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>


                    <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Paid 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>  Pay Amount </label>
                              <input style="height:40px;padding-left:1%;" autofocus="autofocus" onKeyUp="calculate_amount(this.value);" type="text"  required  class="form-control field" name="collected" autocomplete="off" />
                          </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>

          <script>

          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>

      <!-- ending -->

                 </td>

  <!-- Modal -->

  <div class="modal fade" id="againpayChallan<?php echo $details['challan_id'];?>" 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 Again Student Fee   </h4>
        </div>


        <div class="modal-body">

        <h4> <?php echo $student[0]['first_name'];?> <?php echo $student[0]['last_name'];?>  </b>
          (<?php echo $class[0]['Class_Name'];?>)

        </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="AgainAmountPayChallan">
        <input  type="hidden" name="month_name" value="<?php echo $month[0]['Month_Name']; ?>"/>
        <input type="hidden" name="challan_id" value="<?php echo $details['challan_id']; ?>">
        <input type="hidden" name="month_id" value="<?php echo $details['month_id']; ?>">
        <input type="hidden" name="class_id" value="<?php echo $student[0]['class_id']; ?>">
        <input type="hidden" name="session" value="<?php echo $student[0]['session_id']; ?>">
        <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="total_amount" value="<?php echo $totalAmount1; ?>">
        <input type="hidden" name="student" value="<?php echo $_GET['student']; ?>">
       
            

                 <div class="col-md-12" >
                          <div class="form-group" >
                            
                            <label>  Paid Date </label>
                         
        <?php
        $Date = date("Y-m-d");
        $days=' +'.$brid[0]['default_pay_date'].'days';


        ?>

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



 
                     <div class="col-md-12" >
                          <div class="form-group" >
                            
                            <label>  Again Pay Amount </label>
                              <input style="height:40px;padding-left:1%;" autofocus="autofocus" type="text"  required  class="form-control field" autofocus name="again_paid" 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>
 
      <!-- ending -->
      <td id="paid_fee"> 
        <?php echo 0+($details['collected_amount']+$details['collected_fine']+$details['paid_again_amount']+getMoreFee($details['challan_id'],$m));?> / By <?php echo $PaidFeeUser[0]['user_fname'] ?> </td>

      <td id="remaining_fee" style="background-color:pink;"> 
        
        <?php echo $totalAmount1-($details['collected_amount']+$details['collected_fine']+$details['paid_again_amount']);?> </td>

      <td> <?php  if($details['paying_date']!=NULL){ ?>

      <?php echo date("d-M-Y",strtotime($details['paying_date']));?> <br/>

      <?php if ($details['paid_again_date']!=NULL) {

        echo date('d-M-Y', strtotime($details['paid_again_date']));
        ?>

      <?php } }?> </td>

      <td>
         <?php if($details['paid_status']==1 && $access[0]['edit_access']!=NULL){ ?>

                <a data-toggle="modal" data-target="#EditPaidChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-warning">
                  <i class="fa fa-pencil" aria-hidden="true"></i>
                  </a>
                        
                <?php } if( $details['paid_status']==0 && $access[0]['edit_access']!=NULL){ ?>

                <a data-toggle="modal" data-target="#EditChallan<?php echo $details['challan_id'];?>" style="padding: 0px 5px; font-size:14px;" href="#" class="btn btn-success">
                  <i class="fa fa-pencil" aria-hidden="true"></i>
                  </a>
                        
                <?php } ?>

             
                <?php if ($access[0]['delete_access']!=NULL) { ?>
                  
                  <a onclick="return confirm('Are you sure you want to delte this challan???');" style="padding: 0px 5px; font-size:14px;"
                 href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?action=DeleteVoucher&challan=<?php echo $details['challan_id'];?>&month_id=<?php echo $details['month_id'];?>&student_id=<?php echo $_REQUEST['student_id']?>&session=<?php echo $session1?>&TotalAmount=<?php echo $totalAmount1?>&PaidAmount=<?php echo 0+($details['collected_amount']+$details['collected_fine']+$details['paid_again_amount']+getMoreFee($details['challan_id'],$m));?>" class="btn btn-danger">
                  <i class="fa fa-remove" aria-hidden="true"></i>
                </a>

               <?php } ?>
                
                        
                     

            <a data-toggle="modal" data-target="#AddCommitment<?php echo $details['challan_id'];?>" style="padding: 0px 5px;" href="#" class="btn btn-warning"><i class="fa fa-comment" aria-hidden="true"></i></a>
      </td>

    </tr>


<?php 

}
?>            

             </table>

</div>
