

<script>

                 
            $(document).ready(function () {

                prosloadparentcountdownlist();    
                prosloadpaymentcontent();
            });


            function prosloadparentcountdownlist()
            {

                 var UserID = '<?php echo $parentID; ?>';
                 var UserType = '<?php echo $UType; ?>';




                 $.ajax({
                        type: "POST",
                        url: "../../controller/scripts/parent/wallet/loadtimecoundownconten.php",
                        data: {
                            UserID:UserID,
                            UserType:UserType
                        },
                        success: function(output) {

                                    // alert(output);

                            if (output.trim() === '') {
                                    // Handle empty output if needed
                                } else {
                                    try {
                                        var jsonDatacate = JSON.parse(output);

                                        if (Object.keys(jsonDatacate).length > 0) {
                                            var itemnew = jsonDatacate;

                                            // Set values in input fields
                                            $('.prosloadstartcoundown').val(itemnew.startdate);
                                            $('.prosloadendcoundown').val(itemnew.enddate);
                                            $('.prosloadnamecountdown').html(itemnew.name);
                                               
                                             $('#prosloadtotalamountchargefee').html(itemnew.balance);
                                            
                                            
                                             
                                  
                                            $('.prosloadcoundes').html(itemnew.description);


                                            var proloadbalance = itemnew.description;

                                             var starttime = $('.prosloadstartcoundown').val();
                                             var endtime =  $('.prosloadendcoundown').val();
                                                  

                                                var currentDate = new Date();

                                             // Format the date as 'YYYY-MM-DD'
                                              var formattedDate = currentDate.toISOString().split('T')[0];


                                              if(proloadbalance == '0' || proloadbalance == '0.00')
                                              {

                                              }else
                                              {


                                                 if(formattedDate >= endtime)
                                                    {

                                                    }else
                                                    {
                                                        startcountfeedownnow();
                                                    }
                                              }
                                                  

                                                   

                                                 
                                        } else {
                                            console.log("Empty JSON object or unexpected structure.");
                                        }
                                    } catch (error) {
                                        console.log("Error parsing JSON:", error);
                                    }
                                }


                               

                                    
                        }
                });

                 

            }





            function startcountfeedownnow() {
                var starttime = $('.prosloadstartcoundown').val();
                var endtime =  $('.prosloadendcoundown').val();

                // Convert the start and end times to JavaScript Date objects
                let startDate = new Date(starttime);
                let endDate = new Date(endtime);

                let dayBox = document.getElementById("day-box");
                let hrBox = document.getElementById("hr-box");
                let minBox = document.getElementById("min-box");
                let secBox = document.getElementById("sec-box");

                // Output value in milliseconds
                let endTime = endDate.getTime();

                function countdown() {
                    let todayDate = new Date();
                    // Output value in milliseconds
                    let todayTime = todayDate.getTime();

                    let remainingTime = endTime - todayTime;

                    // 60sec => 1000 milliseconds
                    let oneMin = 60 * 1000;
                    // 1hr => 60 minutes
                    let oneHr = 60 * oneMin;
                    // 1 day => 24 hours
                    let oneDay = 24 * oneHr;

                    // Function to format number if it is a single digit
                    let addZeroes = num => num < 10 ? `0${num}` : num;

                    // If end date is before today date
                    if (endTime < todayTime) {
                        clearInterval(i);

                        $('#prosloadcountdowncontent').fadeOut('slow');
                        
                        // document.querySelector(".countdown").innerHTML = `<h1>Countdown had expired!</h1>`;
                    }
                    // If end date is not before today date
                    else {
                        $('#prosloadcountdowncontent').fadeIn('slow');
                        // Calculating remaining days, hrs, mins, secs
                        let daysLeft = Math.floor(remainingTime / oneDay);
                        let hrsLeft = Math.floor((remainingTime % oneDay) / oneHr);
                        let minsLeft = Math.floor((remainingTime % oneHr) / oneMin);
                        let secsLeft = Math.floor((remainingTime % oneMin) / 1000);

                        // Displaying Values
                        dayBox.textContent = addZeroes(daysLeft);
                        hrBox.textContent = addZeroes(hrsLeft);
                        minBox.textContent = addZeroes(minsLeft);
                        secBox.textContent = addZeroes(secsLeft);
                    }
                }

                let i = setInterval(countdown, 1000);
                countdown();
            }


            ///pros load payement content here



            function prosloadpaymentcontent()
            {

                  var UserID = '<?php echo $parentID; ?>';
                 var UserType = '<?php echo $UType; ?>';


                 $('.prosloadfeecontent').html('<div align="center"> <i class="fas fa-spinner fa-spin fs-1" style="color:white;"></i></div>');





                 $.ajax({
                        type: "POST",
                        url: "../../controller/scripts/parent/wallet/prosloadparentschoolfeesummary.php",
                        data: {
                            UserID:UserID,
                            UserType:UserType
                        },
                        success: function(output) {

                            $('.prosloadfeecontent').html(output);

                                    
                        }
                });






                   
            }
            







            
$(document).ready(function () {


prosloadpayementtypecontenthere();    

});


$('body').on('change', '.prosgeneralpaymenttypecheck', function() {
prosloadpayementtypecontenthere();    
});









function prosloadpayementtypecontenthere()
{
  

var UserID = '<?php echo $parentID; ?>';
var UserType = '<?php echo $UType; ?>';
var proscheckedpayementtype = $('.prosgeneralpaymenttypecheck:checked').val();


$('.prosloadcontenttypeinstant').html('<i class="fa fa-spinner fa-spin"></i>');



    $.ajax({
            type: "POST",
            url: "../../controller/scripts/parent/wallet/pros-loadpayementtypecontent.php",
            data: {
                UserID:UserID,
                UserType:UserType,
                proscheckedpayementtype:proscheckedpayementtype
            },
            success: function(output) {


                        $('.prosloadcontenttypeinstant').html(output);
            }
    });



}



            
$('body').on('keyup', '.prospepaymentamount', function () {

        var amount = $(this).val();
        $('#displaybtnamount').html(amount);

});


$('body').on('click', '.prosclionhidetimmercontentbtn', function () {
       
            
      $('.prosloadcountdowncontentcontent').fadeOut();


});



  $('body').on('change', '#proschealstudforpayment', function() {

  

       var checkStatus = $(this).prop('checked');

      

    if(checkStatus == true)
    {
        $(".prosgetsinglestudentforpayment").prop('checked', $(this).prop("checked"));
       
      
    }
    else if(checkStatus == false)
    {

        $(".prosgetsinglestudentforpayment").prop('checked', false);
    }
   



});




$('body').on('click', '.prosmakepaymentbtn', function () {

  
          $('.prosmakepaymentbtn').html('processing..<i class="fa fa-spinner fa-spin"></i>');
                  

                var UserID = '<?php echo $parentID; ?>';
                var UserType = '<?php echo $UType; ?>';

              

                var proscheckedpayementtype = $('.prosgeneralpaymenttypecheck:checked').val();
                var Aamount = $('.prospepaymentamount').val();

                var Aamountpayementtype = $('.prosclassforeacpayementtype').val();

                var d = new Date();
                var n = d.getTime();
                var p = Math.floor((Math.random() * 100) + 1);
                var referencenumber = "RX" + n + "-" + p;


              

                var studentID = [];
                var CampusID = [];
           
          

                $.each($('.prosgetsinglestudentforpayment:checked'),function(){
                            
                            studentID.push($(this).val());
                            CampusID.push($(this).data('id'));
                 });



         
                 if(Aamount == ''){


                        $.wnoty({
                            type: 'warning',
                            message: 'Hey!! Input amount to proceed.',
                            autohideDelay: 5000
                        });


                        $('.prosmakepaymentbtn').html(`PAY ₦ <span id="displaybtnamount">`+Aamount+`</span>
                         <span class="ms-3 fa fa-arrow-right"></span>`);


                 }
                  else if(studentID == '')
                 {


                        $.wnoty({
                            type: 'warning',
                            message: 'Hey!! Select the Child you want to make payment for.',
                            autohideDelay: 5000
                        });

                            $('.prosmakepaymentbtn').html(`PAY ₦ <span id="displaybtnamount">`+Aamount+`</span>
                            <span class="ms-3 fa fa-arrow-right"></span>`);



                 }else if(parseInt(Aamount) > parseInt(Aamountpayementtype) )
                 {
                              


                       $.wnoty({
                            type: 'warning',
                            message: 'Opps!! your '+proscheckedpayementtype+' amount is less than the amount you inputed',
                            autohideDelay: 5000
                        });

                            $('.prosmakepaymentbtn').html(`PAY ₦ <span id="displaybtnamount">`+Aamount+`</span>
                            <span class="ms-3 fa fa-arrow-right"></span>`);


                 }else
                 
                 {


                    $('.prosmakepaymentbtn').prop('disabled', true);


                    $.ajax({
                            type: "POST",
                            url: "../../controller/scripts/parent/wallet/prosmakepaymentforcountdownhere.php",
                            data: {

                                    UserID:UserID,
                                    UserType:UserType,
                                    proscheckedpayementtype:proscheckedpayementtype,
                                    Aamount:Aamount,
                                    Aamountpayementtype:Aamountpayementtype,
                                    CampusID:CampusID,
                                    studentID:studentID,
                                    referencenumber:referencenumber
                            },
                            success: function(output) {

                               

                               

                                      

                                $('.prosmakepaymentbtn').prop('disabled', false);
                                
                                $('.prosmakepaymentbtn').html(`PAY ₦ <span id="displaybtnamount"></span>
                                                     <span class="ms-3 fa fa-arrow-right"></span>`);


                                

                                    if(output.trim() == '1'){


                                          $.wnoty({
                                                type: 'success',
                                                message: 'Great!! Transaction made successfully.',
                                                autohideDelay: 5000
                                            });
                                           



                                            prosloadparentcountdownlist();    
                                             prosloadpaymentcontent();
                                    }else
                                    {

                                                $.wnoty({
                                                        type: 'warning',
                                                        message: 'Hey!! Transaction was not successfull please try again',
                                                        autohideDelay: 5000
                                                    });
                                           

                                    }
                                

                                    
                                                

                                                    
                            }
                    });



                 }

            
  });
      





        

                  


</script>