
<?php

            error_reporting(E_ALL);
            ini_set('display_errors', 1);
            include('../../../config/config.php');

            $UserID = $_POST['UserID'];
            $UserType = $_POST['UserType'];
            $statustype = $_POST['statustype'];

           


             

              


          if($statustype == 'instant')
          {


                          $session = $_POST['session'];

                            $currenttermquery = mysqli_query($link, "SELECT * FROM `termorsemester` WHERE `status`='1'");
                            $currenttermquerycnt =  mysqli_num_rows($currenttermquery);
                            $currenttermquerycnt_row =  mysqli_fetch_assoc($currenttermquery);

                            $TermOrSemesterIDcurrent   = $currenttermquerycnt_row['TermOrSemesterID'];



                            $currentsessionquery = mysqli_query($link, "SELECT * FROM `session` WHERE `sessionStatus`='1'");
                            $currentsessionquerycnt =  mysqli_num_rows($currentsessionquery);
                            $currentsessionquerycnt_row =  mysqli_fetch_assoc($currentsessionquery);

                            $sessionName =  $currentsessionquerycnt_row['sessionName'];

                            


                            $select_studnent =   mysqli_query($link,"SELECT * FROM `parent` INNER JOIN `student`  ON `parent`.`ParentID` = `student`.`ParentID`  WHERE `parent`.`ParentID`='$UserID'");
                            
                            

                            $select_studnent_cnt  = mysqli_fetch_assoc($select_studnent);
                            $select_studnent_cnt_row = mysqli_num_rows($select_studnent);

                            if($select_studnent_cnt_row  > 0)
                            {

                                $num = 1;




                                // echo '<input type="hidden" class="prosgetwallet_amount_school" value="'.$wallet_balanceamount.'">';

                                    echo '<div class="table-responsive"><table class="table" >
                                    <thead style="border:none;">
                                        <tr>
                                            <th scope="col">
                                                <input class="form-check-input prosselectallcheckedall" type="checkbox" value="" >
                                                <label class="form-check-label" for="flexCheckDefault">All</label>
                                            </th>
                                            <th scope="col">Name</th>
                                            <th scope="col">Total Fee</th>
                                            <th scope="col">paid </th>
                                            <th scope="col">Debt </th>
                                        </tr>
                                    </thead>
                                    <tbody></div>';
                                
                    
                    
                    

                                            do{



                                                    $StudentID =  $select_studnent_cnt['StudentID'];
                                                    $StudentFirstName =  $select_studnent_cnt['StudentFirstName'];
                                                    $StudentLastName =  $select_studnent_cnt['StudentLastName'];
                                                    $CampusID =  $select_studnent_cnt['CampusID'];



                                                    $prosp_loadtransaction_cuerrnet = mysqli_query($link,"SELECT SUM(TransactionIn) AS TransactionInamountcurrent FROM `transactions` WHERE CampusID='$CampusID' AND  StudentID='$StudentID' AND `Session`='$sessionName' AND TermOrSemesterID='$TermOrSemesterIDcurrent'");
                                                    $prosp_loadtransaction_cnt_cuerrnet = mysqli_num_rows($prosp_loadtransaction_cuerrnet);
                                                    $prosp_loadtransaction_row_cuerrnet = mysqli_fetch_assoc($prosp_loadtransaction_cuerrnet);
                        
                                                    $proslpaidcuuerntamount = $prosp_loadtransaction_row_cuerrnet['TransactionInamountcurrent'];
                                                    
                        

                                                       if($proslpaidcuuerntamount == '' || $proslpaidcuuerntamount == 'null' ||    $proslpaidcuuerntamount == '0')
                                                       {

                                                              $prospoverallpaid = '0.00';

                                                           
                                                       }else{


                                                                    $prospoverallpaid = number_format($proslpaidcuuerntamount);
                                                       }
                                                    
                                                       



                                                


                                                    $amountoptional_charge = 0;
                                                    $amountcomp_charge = 0;
                            
                                                    $amounttransaction_amount = 0;
                                                    


                                                    //get student classs details here 


                                                    $selectclasss = mysqli_query($link,"SELECT * FROM `classordepartmentstudentallocation` WHERE StudentID='$StudentID' AND CampusID='$CampusID'");
                                                    $selectclassscnt  = mysqli_fetch_assoc($selectclasss);
                                                    $selectclassscnt_row = mysqli_num_rows($selectclasss);


                                                    if( $selectclassscnt > 0)
                                                    {


                                                            do{




                                                                    $ClassOrDepartmentID =  $selectclassscnt['ClassOrDepartmentID'];   
                                                                    $Sessionnew  =  $selectclassscnt['Session'];          
                                                                    $CampusIDnew  =  $selectclassscnt['CampusID'];  




                                                                    $selectcompfee = mysqli_query($link,"SELECT SUM(Amount) AS Amount FROM
                                                                    `chargestructure` WHERE ClassOrDepartmentID='$ClassOrDepartmentID' AND `Session`='$Sessionnew'  AND CampusID='$CampusIDnew' AND Status='1'");



                                                                    $selectcompfee_cnt_row = mysqli_fetch_assoc($selectcompfee);
                                                                    $selectcompfee_cnt = mysqli_num_rows($selectcompfee);



                                                                    $compamount = $selectcompfee_cnt_row['Amount'];
                                                                    

                                                                    
                                                                    $amountcomp_charge += $compamount;

                                                                    $selectoptfee = mysqli_query($link,"SELECT SUM(Amount) AS Amountoptional FROM `chargestructure`
                                                                    INNER JOIN `assignoptionalfees` ON `chargestructure`.`SubcategoryID`
                                                                    = `assignoptionalfees`.`SubcategoryID` WHERE 
                                                                    `chargestructure`.`Status`='0' AND `assignoptionalfees`.`StudentID`='$StudentID'
                                                                    AND `assignoptionalfees`.`Status`='0' AND `chargestructure`.`ClassOrDepartmentID`='$ClassOrDepartmentID' 
                                                                    AND `chargestructure`.`Session`='$Sessionnew' AND `chargestructure`.`CampusID`='$CampusIDnew'");



                                                                        $selectoptfee_cnt_row = mysqli_fetch_assoc($selectoptfee);
                                                                        $selectoptfee_cnt = mysqli_num_rows($selectoptfee);



                                                                    $compamount_optional =     $selectoptfee_cnt_row ['Amountoptional'];
                                                                    $amountoptional_charge +=$compamount_optional;


                                                                    $prosp_loadtransaction = mysqli_query($link,"SELECT SUM(TransactionIn) AS TransactionInamount FROM `transactions` WHERE CampusID='$CampusIDnew' AND  StudentID='$StudentID' AND `Session`='$Sessionnew' AND ClassOrDepartmentID='$ClassOrDepartmentID'");
                                                                    $prosp_loadtransaction_cnt = mysqli_num_rows($prosp_loadtransaction);
                                                                    $prosp_loadtransaction_row = mysqli_fetch_assoc($prosp_loadtransaction);


                                                                    $TransactionInamount =   $prosp_loadtransaction_row ['TransactionInamount'];

                                                                    $amounttransaction_amount +=$TransactionInamount;



                                                            }while($selectclassscnt  = mysqli_fetch_assoc($selectclasss));
                                                                

                                                    }else
                                                    {

                                                    }
                                        

                                                    

                                                    $prostotalcharge = $amountoptional_charge  + $amountcomp_charge; 

                                                    if($amounttransaction_amount >= $prostotalcharge)
                                                    {
                            
                                                        $prostotalchargeoverall = '0.00';
                            
                                                    }else{
                            
                            
                                                        $prostotalchargeoverall = number_format($prostotalcharge -  $amounttransaction_amount);
                            
                                                    }


                            
                                                    
                                                    $prosamountchargetotal = number_format($prostotalcharge);
                                                


                                                    if(intval($amounttransaction_amount) >= intval($prostotalcharge))
                                                    {
                                                                $classname = '';
                                                                $disablechecked = 'disabled';
                                                                $background = "gray";
                                                                
                                                    }else
                                                    {


                                                        $classname = 'proscheckedainputnamesalaryeach';
                                                        $disablechecked = '';
                                                        $background = '';
                                                        
                                                    }


                                                

                                                
                                                    
                                                echo' <tr>
                                                        <td><input '.$disablechecked.'  style="background:'.$background.';" class="form-check-input '.$classname.'"  data-amount="'.$prostotalchargeoverall.'"  data-id="'.$CampusID.'" value="'.$StudentID.'" type="checkbox" ></td>
                                                        <td>'.$StudentFirstName.' '. $StudentLastName.'</td>
                                                        <td>₦ '.$prosamountchargetotal.'</td>
                                                    
                                                    <td>₦'. $prospoverallpaid.'</td>
                                                    <td>₦ '.$prostotalchargeoverall.'</td>
                                                    </tr>';



                                            }while($select_studnent_cnt  = mysqli_fetch_assoc($select_studnent));  
                                            
                                            
                                    
                            echo '</tbody>
                            </table>';
                                    
                            }




          }else{


                            $currenttermquery = mysqli_query($link, "SELECT * FROM `termorsemester` WHERE `status`='1'");
                            $currenttermquerycnt =  mysqli_num_rows($currenttermquery);
                            $currenttermquerycnt_row =  mysqli_fetch_assoc($currenttermquery);

                            $TermOrSemesterIDcurrent   = $currenttermquerycnt_row['TermOrSemesterID'];



                            $currentsessionquery = mysqli_query($link, "SELECT * FROM `session` WHERE `sessionStatus`='1'");
                            $currentsessionquerycnt =  mysqli_num_rows($currentsessionquery);
                            $currentsessionquerycnt_row =  mysqli_fetch_assoc($currentsessionquery);

                            $sessionName =  $currentsessionquerycnt_row['sessionName'];

                            


                            $select_studnent =   mysqli_query($link,"SELECT * FROM `parent` INNER JOIN `student`  ON `parent`.`ParentID` = `student`.`ParentID`  WHERE `parent`.`ParentID`='$UserID'");
                            
                            

                            $select_studnent_cnt  = mysqli_fetch_assoc($select_studnent);
                            $select_studnent_cnt_row = mysqli_num_rows($select_studnent);

                            if($select_studnent_cnt_row  > 0)
                            {

                                $num = 1;




                                // echo '<input type="hidden" class="prosgetwallet_amount_school" value="'.$wallet_balanceamount.'">';

                                    echo '<div class="table-responsive"><table class="table" >
                                    <thead style="border:none;">
                                        <tr>
                                            <th scope="col">
                                                <input class="form-check-input prosselectallcheckedall_schedule" type="checkbox" value="" >
                                                <label class="form-check-label" for="flexCheckDefault_shedule">All</label>
                                            </th>
                                            <th scope="col">Name</th>
                                            <th scope="col">Total Fee</th>
                                            <th scope="col">paid </th>
                                            <th scope="col">Debt </th>
                                        </tr>
                                    </thead>
                                    <tbody></div>';
                                
                    
                    
                    

                                            do{



                                                    $StudentID =  $select_studnent_cnt['StudentID'];
                                                    $StudentFirstName =  $select_studnent_cnt['StudentFirstName'];
                                                    $StudentLastName =  $select_studnent_cnt['StudentLastName'];
                                                    $CampusID =  $select_studnent_cnt['CampusID'];



                                                    $prosp_loadtransaction_cuerrnet = mysqli_query($link,"SELECT SUM(TransactionIn) AS TransactionInamountcurrent FROM `transactions` WHERE CampusID='$CampusID' AND  StudentID='$StudentID' AND `Session`='$sessionName' AND TermOrSemesterID='$TermOrSemesterIDcurrent'");
                                                    $prosp_loadtransaction_cnt_cuerrnet = mysqli_num_rows($prosp_loadtransaction_cuerrnet);
                                                    $prosp_loadtransaction_row_cuerrnet = mysqli_fetch_assoc($prosp_loadtransaction_cuerrnet);
                        
                                                    $proslpaidcuuerntamount = $prosp_loadtransaction_row_cuerrnet['TransactionInamountcurrent'];
                                                    
                        
                                                    
                                                       

                                                        if($proslpaidcuuerntamount == '' || $proslpaidcuuerntamount == 'null' ||    $proslpaidcuuerntamount == '0')
                                                        {
 
                                                               $prospoverallpaid = '0.00';
 
                                                            
                                                        }else{
 
 
                                                                     $prospoverallpaid = number_format($proslpaidcuuerntamount);
                                                        }
                                                     

                                                


                                                    $amountoptional_charge = 0;
                                                    $amountcomp_charge = 0;
                            
                                                    $amounttransaction_amount = 0;
                                                    


                                                    //get student classs details here 


                                                    $selectclasss = mysqli_query($link,"SELECT * FROM `classordepartmentstudentallocation` WHERE StudentID='$StudentID' AND CampusID='$CampusID'");
                                                    $selectclassscnt  = mysqli_fetch_assoc($selectclasss);
                                                    $selectclassscnt_row = mysqli_num_rows($selectclasss);


                                                    if( $selectclassscnt > 0)
                                                    {


                                                            do{




                                                                    $ClassOrDepartmentID =  $selectclassscnt['ClassOrDepartmentID'];   
                                                                    $Sessionnew  =  $selectclassscnt['Session'];          
                                                                    $CampusIDnew  =  $selectclassscnt['CampusID'];  




                                                                    $selectcompfee = mysqli_query($link,"SELECT SUM(Amount) AS Amount FROM
                                                                    `chargestructure` WHERE ClassOrDepartmentID='$ClassOrDepartmentID' AND `Session`='$Sessionnew'  AND CampusID='$CampusIDnew' AND Status='1'");



                                                                    $selectcompfee_cnt_row = mysqli_fetch_assoc($selectcompfee);
                                                                    $selectcompfee_cnt = mysqli_num_rows($selectcompfee);



                                                                    $compamount = $selectcompfee_cnt_row['Amount'];
                                                                    

                                                                    
                                                                    $amountcomp_charge += $compamount;

                                                                    $selectoptfee = mysqli_query($link,"SELECT SUM(Amount) AS Amountoptional FROM `chargestructure`
                                                                    INNER JOIN `assignoptionalfees` ON `chargestructure`.`SubcategoryID`
                                                                    = `assignoptionalfees`.`SubcategoryID` WHERE 
                                                                    `chargestructure`.`Status`='0' AND `assignoptionalfees`.`StudentID`='$StudentID'
                                                                    AND `assignoptionalfees`.`Status`='0' AND `chargestructure`.`ClassOrDepartmentID`='$ClassOrDepartmentID' 
                                                                    AND `chargestructure`.`Session`='$Sessionnew' AND `chargestructure`.`CampusID`='$CampusIDnew'");



                                                                        $selectoptfee_cnt_row = mysqli_fetch_assoc($selectoptfee);
                                                                        $selectoptfee_cnt = mysqli_num_rows($selectoptfee);



                                                                    $compamount_optional =     $selectoptfee_cnt_row ['Amountoptional'];
                                                                    $amountoptional_charge +=$compamount_optional;


                                                                    $prosp_loadtransaction = mysqli_query($link,"SELECT SUM(TransactionIn) AS TransactionInamount FROM `transactions` WHERE CampusID='$CampusIDnew' AND  StudentID='$StudentID' AND `Session`='$Sessionnew' AND ClassOrDepartmentID='$ClassOrDepartmentID'");
                                                                    $prosp_loadtransaction_cnt = mysqli_num_rows($prosp_loadtransaction);
                                                                    $prosp_loadtransaction_row = mysqli_fetch_assoc($prosp_loadtransaction);


                                                                    $TransactionInamount =   $prosp_loadtransaction_row ['TransactionInamount'];

                                                                    $amounttransaction_amount +=$TransactionInamount;



                                                            }while($selectclassscnt  = mysqli_fetch_assoc($selectclasss));
                                                                

                                                    }else
                                                    {

                                                    }
                                        

                                                    

                                                    $prostotalcharge = $amountoptional_charge  + $amountcomp_charge; 

                                                    if($amounttransaction_amount >= $prostotalcharge)
                                                    {
                            
                                                        $prostotalchargeoverall = '0.00';
                            
                                                    }else{
                            
                            
                                                        $prostotalchargeoverall = number_format($prostotalcharge -  $amounttransaction_amount);
                            
                                                    }


                            
                                                    
                                                    $prosamountchargetotal = number_format($prostotalcharge);
                                                


                                                    if(intval($amounttransaction_amount) >= intval($prostotalcharge))
                                                    {
                                                                $classname = '';
                                                                $disablechecked = 'disabled';
                                                                $background = "gray";
                                                                
                                                    }else
                                                    {


                                                        $classname = 'proscheckedainputnamesalaryeach_schedule';
                                                        $disablechecked = '';
                                                        $background = '';
                                                        
                                                    }


                                                

                                                
                                                    
                                                echo' <tr>
                                                        <td><input '.$disablechecked.'  style="background:'.$background.';" class="form-check-input '.$classname.'" data-studname="'.$StudentFirstName.' '. $StudentLastName.'"  data-amount="'.$prostotalchargeoverall.'"  data-id="'.$CampusID.'" value="'.$StudentID.'" type="checkbox" ></td>
                                                        <td>'.$StudentFirstName.' '. $StudentLastName.'</td>
                                                        <td>₦ '.$prosamountchargetotal.'</td>
                                                    
                                                    <td>₦'. $prospoverallpaid.'</td>
                                                    <td>₦ '.$prostotalchargeoverall.'</td>
                                                    </tr>';



                                            }while($select_studnent_cnt  = mysqli_fetch_assoc($select_studnent));  
                                            
                                            
                                    
                            echo '</tbody>
                            </table>';
                                    
                            }




          }
          



?>