<?php
include('header.php');


$success_message = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Loop through the services and update their prices in the database
    $services = [
        'aadhaaar_e-KYC_fee', 'aadhar_manual_fee', 'rc_vehical_fee', 'Aadhaar_To_Pan_find', 'pan_details_verify',
        'instant_pan_manual_fee', 'voter_manual_flx', 'v_mobile_link',
        'Driving_Licence_Pdf', 'Driving_Licence_Find', 'challan_fee', 'esharm_fee', 'Airtel_pas',
       'Fino_pass_fee', 'Ippb_pass_fee',  'Mobile_Operator_check', 'Pin_code_Fee',
        'voter_pdf_instant', 'ration_pdf_flx_print_fee', 'adhaar_to_ration_details',
       'ration2_uid_findfee', 'convert_PVC_fee' , 'gst_verification' , 'janAaadhar_PDF_fee' , 'janadhar_find_fee'
       , 'electricBill_details_fee' , 'dbt_farmer_fee' , 'elctricbill_pdf_fee' , 'ehsram_details_find' , 'pan_adhaar_status' , 'eshram_pdf', 'pan_adhaar_mask'
       , 'ennrollment_status_fee', 'aadhaar_verify_fee', 'ifsc_Verification_fee' , 'bihar_rtps_all' , 'bike_2_whiller_fee', 'all_petrol_and_cng_fee',
       'all_diesel_fee' , 'normal_puc_fee', 'll_request_fee', 'Tec_fee', 'new_pan_request', 'Pan_To_Aadhaar_find' , 'agri_stack_fee', 'AgriFarmer_PDF_Fee',
       'HaryanaFaimly_Charge', 'Chassic_rc_find', 'npci_status_check'
    ];

    // Flag to check if at least one update was successful
    $update_successful = false;

    foreach ($services as $service) {
        if (isset($_POST[$service])) {
            $new_price = $_POST[$service];

            // Update the price in the database for the specific service
            $query = "UPDATE pricing SET price='$new_price' WHERE service_name='$service'";
            if (mysqli_query($ahk_conn, $query)) {
                $update_successful = true;
            }
        }
    }

    // If update is successful, set success message
    if ($update_successful) {
        $success_message = "Prices updated successfully!";
    }
}
?>

<!--start page wrapper -->
<div class="page-wrapper">
    <div class="page-content">
        <!--breadcrumb-->
        <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
           
            <div class="ps-3">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb mb-0 p-0">
                        <li class="breadcrumb-item"><a href="javascript:;"><i class="bx bx-home-alt"></i></a></li>
                        <li class="breadcrumb-item active" aria-current="page">Website Pricing</li>
                    </ol>
                </nav>
            </div>
            <div class="ms-auto">
                <div class="btn-group">
                  
                    </div>
                </div>
            </div>
        </div>
        <!--end breadcrumb-->
        
        <?php 
        // Fetch the current pricing details from the database
        $pricing = [];
        $services = [
            'aadhaaar_e-KYC_fee', 'aadhar_manual_fee', 'rc_vehical_fee', 'Aadhaar_To_Pan_find', 'pan_details_verify',
            'instant_pan_manual_fee', 'voter_manual_flx', 'v_mobile_link',
            'Driving_Licence_Pdf', 'Driving_Licence_Find', 'challan_fee','esharm_fee', 'Airtel_pas',
            'Fino_pass_fee', 'Ippb_pass_fee',  'Mobile_Operator_check', 'Pin_code_Fee',
            'voter_pdf_instant', 'ration_pdf_flx_print_fee', 'adhaar_to_ration_details',
            'ration2_uid_findfee', 'convert_PVC_fee', 'gst_verification' , 'janAaadhar_PDF_fee' , 'janadhar_find_fee'
       , 'electricBill_details_fee' , 'dbt_farmer_fee' , 'elctricbill_pdf_fee' , 'ehsram_details_find' , 'pan_adhaar_status' , 'eshram_pdf', 'pan_adhaar_mask'
       , 'ennrollment_status_fee', 'aadhaar_verify_fee' , 'ifsc_Verification_fee', 'bihar_rtps_all' , 'bike_2_whiller_fee', 'all_petrol_and_cng_fee',
       'all_diesel_fee' , 'normal_puc_fee', 'll_request_fee', 'Tec_fee', 'new_pan_request', 'Pan_To_Aadhaar_find', 'agri_stack_fee', 'AgriFarmer_PDF_Fee',
       'HaryanaFaimly_Charge', 'Chassic_rc_find', 'npci_status_check'
        ];

        foreach ($services as $service) {
            $result = mysqli_query($ahk_conn, "SELECT * FROM pricing WHERE service_name='$service'");
            $pricing[$service] = mysqli_fetch_assoc($result);
        }
        ?>

        <div class="row">
            <div class="col-xl-10 mx-auto">
               
               
                <div class="card border-top border-0 border-4 border-primary">
                    <div class="card-body p-5">
                        <div class="card-title d-flex align-items-center">
                            <div><i class="bx bxs-cog me-1 font-22 text-primary"></i></div>
                            <h5 class="mb-0 text-primary">Update Pricing Details</h5>
                        </div>
                        <hr>
                        <form action="" method="POST" class="row g-3">
                            <?php
                            // Iterate over all services and create input fields dynamically
                            foreach ($services as $service) {
                                $service_name = ucwords(str_replace('_', ' ', $service)); // format service name for display
                                $service_price = isset($pricing[$service]['price']) ? $pricing[$service]['price'] : ''; // get the price from the database
                            ?>
                                <div class="col-md-3">
                                    <label for="input<?php echo $service; ?>" class="form-label"><?php echo $service_name; ?></label>
                                    <input name="<?php echo $service; ?>" value="<?php echo $service_price; ?>" type="text" placeholder="<?php echo $service_name; ?>" class="form-control" id="input<?php echo $service; ?>">
                                </div>
                            <?php } ?>
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary px-5">Save</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

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

<!-- SweetAlert2 Script -->
<?php if ($success_message != ''): ?>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: '<?php echo $success_message; ?>',
            confirmButtonText: 'OK'
        });
    </script>
<?php endif; ?>


	<!-- Bootstrap JS -->
	

	<script src="../template/ahkweb/assets/js/bootstrap.bundle.min.js"></script>
	<!--plugins-->
	<!-- <script src="../template/ahkweb/assets/js/jquery.min.js"></script> -->
	<script src="../template/ahkweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
	<script src="../template/ahkweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
	<script src="../template/ahkweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
	<!--app JS-->
	<script src="../template/ahkweb/assets/js/app.js"></script>
</body>

<script>
	// $(document).ready(function() {
	
	// $('#eid').inputmask();
	// $('#date').inputmask();
	// $('#timea').inputmask("hh:mm:ss", {
    //     placeholder: "00:00:00", 
    //     insertMode: false, 
    //     showMaskOnHover: false,
    //     hourFormat: 12
    //   });
	// });
</script>
</html>