JezK
Edit File: careclub.php
<?php include('userObject.php'); if (isset($_POST['limit'])) { $careClubsData = $user->getCareClubs($_POST['branchId']); $branchId = $_POST['branchId']; $data = ''; $count = 0; foreach ($careClubsData as $row) { $displayAmount = '...'; $allServiceIds = []; $serviceCountMap = []; for ($y = 1; $y <= 5; $y++) { $yearServices = json_decode($row["services_{$y}_year"], true) ?? []; foreach ($yearServices as $sid => $count) { $allServiceIds[] = $sid; if (!isset($serviceCountMap[$sid])) { $serviceCountMap[$sid] = 0; } $serviceCountMap[$sid] += (int)$count; } } $allServiceIds = array_unique($allServiceIds); $data .= ' <div class="col-sm-6 col-md-3 mt-3 pc-md-3"> <div class="package-box"> <div class="row mt-2"> <div class="col-md-12"> <p class="pc-title text-center mh-4">' . $row['name'] . '</p> </div> </div> <div class="package-name"> <div class="d-flex flex-column justify-content-space-around align-items-baseline"> <div style="font-weight: bold;"><i class="fa fa-car-side" style="color:#00adef; padding-right: 10px;"></i>Select Car Type</div> <select class="form-select w-100 carType' . $row['care_club_id'] . '" id="carTypeFilter" style="font-weight: bold; border-color: #00adef;"> <option value="0">Select Car</option> <option value="4"><i class="fa fa-car-alt" style="color:#00adef; padding-right: 10px;"></i>Hatchback</option> <option value="1"><i class="fa fa-car" style="color:#00adef; padding-right: 10px;"></i>Sedan</option> <option value="3"><i class="fa fa-car-side" style="color:#00adef; padding-right: 10px;"></i>MUV</option> <option value="2"><i class="fa fa-truck" style="color:#00adef; padding-right: 10px;"></i>SUV</option> </select> </div> <div class="d-flex flex-column justify-content-space-around align-items-baseline"> <div style="font-weight: bold;"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i>Select Plan</div> <select class="form-select w-100 plan' . $row['care_club_id'] . '" id="planFilter" style="font-weight: bold; border-color: #00adef;"> <option value="0">Select Plan</option> <option value="1"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 1 Year</option> <option value="2"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 2 Years</option> <option value="3"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 3 Years</option> <option value="4"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 4 Years</option> <option value="5"><i class="fas fa-calendar-alt" style="color:#00adef; padding-right: 10px;"></i> 5 Years</option> </select> </div> <p class="pc-price" style="padding: 15px 0 15px 0;"><i class="fas fa-rupee-sign" style="color:#00adef; padding-right: 10px;"></i> RS. ' . $displayAmount . '</p>'; $data .= ' </div> <div class="features"> <ul class="features-list">'; $count = 0; foreach ($allServiceIds as $sid) { if ($count === 2) break; $service = $user->getSingleserviceDetails($sid); if (!$service) continue; // $data .= '<li>'. $service['name']. ' (' . $serviceCountMap[$sid] . ')' . '</li>'; $data .= '<li>' . $service['name'] . '</li>'; $count++; } $data .= ' </ul> </div> <button class="no-btn vm" id="packageId' . $row['care_club_id'] . '" onclick="viewServices(' . $row['care_club_id'] . ')">View More </button> <div class="d-flex justify-content-center"> <div class="d-flex justify-content-center mt-3 buyCareClub"> <button type="button" class="buy-btn ms-1" data-toggle="modal" data-target="#cpnModal" data-careclub-id="' . $row['care_club_id'] . '" onclick="setCareClubData(' . $row['care_club_id'] . ',' . $branchId . ',' . $displayAmount . ')">Buy Now</button> </div> </div> </div> </div>'; } echo $data; } if (isset($_POST['services'])) { $result = $user->getServicesByCareClub($_POST['packageId']); $data = ''; foreach ($result as $row) { $data .= '<ul class=""><li>' . $row['name'] . '</li></ul>'; } echo $data; } if (isset($_POST['action']) && $_POST['action'] == "getCareclubPrice") { $carType = intval($_POST['carType']); $planType = intval($_POST['planType']); $carClubId = intval($_POST['careClubId']); $branchId = intval($_POST['branchId']); if ($carType == 0) { echo json_encode(["status" => "error", "message" => "Please select car type"]); exit; } // Fetch service details from database $careClubData = $user->getCareClubDataById($carClubId, $branchId); // Function to fetch service details if ($careClubData) { $amount = 0; $carName = ""; $priceColumn = ""; switch ($carType) { case 1: $carName = "Sedan"; $priceColumn = "sedan_price_" . $planType . "_year"; break; case 2: $carName = "SUV"; $priceColumn = "suv_price_" . $planType . "_year"; break; case 3: $carName = "MUV"; $priceColumn = "muv_price_" . $planType . "_year"; break; case 4: $carName = "Hatchback"; $priceColumn = "hb_price_" . $planType . "_year"; break; default: echo json_encode(["status" => "error", "message" => "Invalid car type"]); exit; } switch ($planType) { case 1: $careClubServiceDetails = json_decode($careClubData['services_1_year'], true); break; case 2: $careClubServiceDetails = json_decode($careClubData['services_2_year'], true); break; case 3: $careClubServiceDetails = json_decode($careClubData['services_3_year'], true); break; case 4: $careClubServiceDetails = json_decode($careClubData['services_4_year'], true); break; case 5: $careClubServiceDetails = json_decode($careClubData['services_5_year'], true); break; } // print_r($careClubServiceDetails); // exit; $serviceDetailsHtml = ''; foreach ($careClubServiceDetails as $id => $count) { $serviceDetails = $user->getSingleserviceDetails($id); // print_r($serviceDetails); $serviceDetailsHtml .= '<li> ' . $serviceDetails['name'] . ' (' . $count . ') </li>'; } if (isset($careClubData[$priceColumn])) { $amount = $careClubData[$priceColumn]; } else { echo json_encode(["status" => "error", "message" => "Price not available for selected plan"]); exit; } echo json_encode(["status" => "success", "amount" => $amount, "carName" => $carName, "serviceDetails" => $serviceDetailsHtml]); } else { echo json_encode(["status" => "error", "message" => "Service not found"]); } } if (isset($_POST['couponCheck'])) { $couponDetails = $user->checkSecretCoupon($_POST); echo json_encode($couponDetails); }