JezK
Edit File: productsPayments.php
<?php include('adminObject.php'); include('./checkSession.php'); // Document Dot Get Ready if (isset($_POST['getproduct'])) { $data = array(); $productId = $_POST['getproduct']; $selectedProductDetails = $admin->getSingleProductDetails($productId); $data['selectedProductDetails'] = $selectedProductDetails; $where['type'] = 3; $products = $admin->getProducts($where); $services = $admin->getServices($where); $data['selectedItem'] = ' <div class="col-lg-2 col-4"> <div class="card card-p"> <div class="card-header text-right"> <button type="button" class="no-btn close" aria-label="Close" onclick="removeProduct(' . $selectedProductDetails['product_id'] . ')"> <span class="close-ico" aria-hidden="true">×</span> </button> </div> <img src="' . $selectedProductDetails['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"> </h5> <p class="card-text pop-description"> ' . $selectedProductDetails['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $selectedProductDetails['amount'] . ' </p> <div class="input-group product"> <button type="button" class="decrease increment-left" value="' . $selectedProductDetails['product_id'] . '">-</button> <input type="text" class="quantity form-control" value="1" id="quanity' . $selectedProductDetails['product_id'] . '" readonly> <button type="button" class="increment-right increase" value="' . $selectedProductDetails['product_id'] . '">+</button> </div> </div> </div> </div> <div class="col-lg-2 col-4 d-flex align-items-center"> <div class="card card-plus"> <div class="card-body"> <button data-bs-toggle="modal" data-bs-target="#addproduct" class="no-btn plus">+</button> </div> </div> </div>'; // Appending Products Data To Product Modal $data['products'] = ''; foreach ($products as $row) { if ($selectedProductDetails['product_id'] != $row['product_id']) { $data['products'] .= ' <div class="col-lg-2 col-4"> <div class="card cardheight"> <img src="' . $baseUrl . 'uploads/products/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"></h5> <p class="pop-description ">' . $row['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $row['amount'] . '</p> <div class="input-group"> <button type="submit" class="selectbtn" onclick="updateSelectedProducts(this.id,1)" id="productId' . $row['product_id'] . '">Select</button> </div> </div> </div> </div> '; } else { $data['products'] .= ' <div class="col-lg-2 col-4"> <div class="card cardheight"> <img src="' . $baseUrl . 'uploads/products/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"></h5> <p class="pop-description">' . $row['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $row['amount'] . '</p> <div class="input-group"> <button type="submit" class="unselectbtn" onclick="updateSelectedProducts(this.id,2)" id="productId' . $row['product_id'] . '">Un select</button> </div> </div> </div> </div> '; } } // Appending Services Data To Services Modal $data['services'] = ''; foreach ($services as $row) { $data['services'] .= ' <div class="col-lg-2 col-4 service-box"> <div class="card card-p"> <img src="' . $baseUrl . 'uploads/services/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center">' . $row['name'] . '</h5> <select class="form-select" id="carTypeFilter" style="font-weight: bold; border-color: #00adef; width: fit-content;"> <option value="0">Select Car</option> <option value="4">Hatchback</option> <option value="1">Sedan</option> <option value="3">MUV</option> <option value="2">SUV</option> </select> <p class="card-text text-center product-price">Rs. 0.00</p> <div class="input-group"> <button type="button" class="selectbtn" data-service-id="' . $row['service_id'] . '" onclick="updateSelectedServices(this.id,1,0)" id="serviceId' . $row['service_id'] . '" disabled>Select</button> </div> </div> </div> </div>'; } echo json_encode($data); } // Product Modal Data When Selecting And Unselecting Product if (isset($_POST['ProductsIds'])) { $selectedService = json_decode($_POST['ServicesIds']); $selectedProducts = json_decode($_POST['ProductsIds']); $productQuantity = json_decode($_POST['productQuantity']); $selectedServiceCarTypes = json_decode($_POST['selectedServiceCarTypes']); $selectedServiceLength = count($selectedService); $selectedProductsLength = count($selectedProducts); $where['type'] = 3; $products = $admin->getProducts($where); $data = array(); $data['modal'] = ''; foreach ($products as $row) { if (in_array($row['product_id'], $selectedProducts)) { $data['modal'] .= ' <div class="col-lg-2 col-4"> <div class="card cardheight"> <img src="' . $baseUrl . 'uploads/products/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"></h5> <p class="card-text text-center pc-description">' . $row['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $row['amount'] . '</p> <div class="input-group"> <button type="submit" class="unselectbtn" onclick="updateSelectedProducts(this.id,2)" id="productId' . $row['product_id'] . '">Un select</button> </div> </div> </div> </div> '; } else { $data['modal'] .= ' <div class="col-lg-2 col-4"> <div class="card cardheight"> <img src="' . $baseUrl . 'uploads/products/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"></h5> <p class="card-text text-center pc-description">' . $row['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $row['amount'] . '</p> <div class="input-group"> <button type="submit" class="selectbtn" onclick="updateSelectedProducts(this.id,1)" id="productId' . $row['product_id'] . '">Select</button> </div> </div> </div> </div> '; } } $data['selectedItem'] = ''; $productsTotalCost = 0; for ($i = 0; $i < $selectedProductsLength; $i++) { $selectedProductDetails = $admin->getSingleProductDetails($selectedProducts[$i]); $productCostWithQuantity = $selectedProductDetails['amount'] * $productQuantity[$i]; $data['selectedItem'] .= ' <div class="col-lg-2 col-4"> <div class="card cardheight"> <div class="card-header text-right" > <button type="button" class="no-btn close" aria-label="Close" onclick="removeProduct(' . $selectedProductDetails['product_id'] . ')"> <span class="close-ico" aria-hidden="true">×</span> </button> </div> <img src="' . $selectedProductDetails['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center"> </h5> <p class="card-text text-center pc-description"> ' . $selectedProductDetails['name'] . '</p> <p class="card-text text-center product-price">Rs.' . $selectedProductDetails['amount'] . ' </p> <div class="input-group product"> <button type="button" class="decrease increment-left" value="' . $selectedProductDetails['product_id'] . '">-</button> <input type="text" class="quantity form-control" value="' . $productQuantity[$i] . '" id="quanity' . $selectedProductDetails['product_id'] . '" readonly> <button type="button" class="increment-right increase" id="increase" value="' . $selectedProductDetails['product_id'] . '">+</button> </div> </div> </div> </div> '; $data['productsNames'][$i] = $selectedProductDetails['name']; $data['productsCosts'][$i] = $selectedProductDetails['amount'] * $productQuantity[$i]; $data['productsCount'][$i] = $productQuantity[$i]; $productsTotalCost = $productsTotalCost + $productCostWithQuantity; } $data['selectedItem'] .= ' <div class="col-lg-2 col-4"> <div class="card card-plus"> <div class="card-body"> <button data-bs-toggle="modal" data-bs-target="#addproduct" class="no-btn plus">+</button> </div> </div> </div>'; $totalServicesCost = 0; for ($i = 0; $i < $selectedServiceLength; $i++) { $selectedItem = $admin->getSingleserviceDetails($selectedService[$i]); $amount = 0; switch ($selectedServiceCarTypes[$i]) { case 1: $amount = $selectedItem['sedan_amount']; break; case 2: $amount = $selectedItem['suv_amount']; break; case 3: $amount = $selectedItem['muv_amount']; break; case 4: $amount = $selectedItem['hb_amount']; break; } $data['servicesNames'][$i] = $selectedItem['name']; $data['servicesCosts'][$i] = $amount; $totalServicesCost = array_sum($data['servicesCosts']); } $data['totalCost'] = $totalServicesCost + $productsTotalCost; echo json_encode($data); } // Services Modal Data When Selecting And Unselecting Services if (isset($_POST['selectedServicesIds'])) { $selectedService = json_decode($_POST['selectedServicesIds']); $selectedProducts = json_decode($_POST['selectedProductsIds']); $productQuantity = json_decode($_POST['productQuantity']); $selectedServiceCarTypes = json_decode($_POST['selectedServiceCarTypes']); $selectedServiceLength = count($selectedService); $selectedProductsLength = count($selectedProducts); $where['type'] = 3; $services = $admin->getServices($where); $data = array(); // For Services Modal $data['modal'] = ''; foreach ($services as $row) { if (in_array($row['service_id'], $selectedService)) { // Find the index of serviceId in selectedService $index = array_search($row['service_id'], $selectedService); // Get the corresponding carType from selectedServiceCarTypes, default to 0 if not found $selectedCarType = ($index !== false && isset($selectedServiceCarTypes[$index])) ? $selectedServiceCarTypes[$index] : 0; switch ($selectedCarType) { case 1: $amount = $row['sedan_amount']; break; case 2: $amount = $row['suv_amount']; break; case 3: $amount = $row['muv_amount']; break; case 4: $amount = $row['hb_amount']; break; } $data['modal'] .= ' <div class="col-lg-2 col-4 service-box"> <div class="card card-p"> <img src="' . $baseUrl . 'uploads/services/' . $row['image_name'] . '" class="m-img card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center">' . $row['name'] . '</h5> <select class="form-select" id="carTypeFilter" style="font-weight: bold; border-color: #00adef; width: fit-content;"> <option value="0" ' . ($selectedCarType == 0 ? 'selected' : '') . '>Select Car</option> <option value="4" ' . ($selectedCarType == 4 ? 'selected' : '') . '>Hatchback</option> <option value="1" ' . ($selectedCarType == 1 ? 'selected' : '') . '>Sedan</option> <option value="3" ' . ($selectedCarType == 3 ? 'selected' : '') . '>MUV</option> <option value="2" ' . ($selectedCarType == 2 ? 'selected' : '') . '>SUV</option> </select> <p class="card-text text-center product-price">Rs.' . $amount . '</p> <div class="input-group "> <button type="button" class="unselectbtn" data-service-id="' . $row['service_id'] . '" onclick="updateSelectedServices(this.id,2)" id="serviceId' . $row['service_id'] . '" disabled>Unselect</button> </div> </div> </div> </div>'; } else { $data['modal'] .= ' <div class="col-lg-2 col-4 service-box"> <div class="card card-p"> <img src="' . $baseUrl . 'uploads/services/' . $row['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center">' . $row['name'] . '</h5> <select class="form-select" id="carTypeFilter" style="font-weight: bold; border-color: #00adef; width: fit-content;"> <option value="0">Select Car</option> <option value="4">Hatchback</option> <option value="1">Sedan</option> <option value="3">MUV</option> <option value="2">SUV</option> </select> <p class="card-text text-center product-price">Rs. 0.00</p> <div class="input-group"> <button type="button" class="selectbtn" data-service-id="' . $row['service_id'] . '" onclick="updateSelectedServices(this.id,1,0)" id="serviceId' . $row['service_id'] . '" disabled>Select</button> </div> </div> </div> </div>'; } } // For Showing in Selected Items(At End Page) $data['selectedItem'] = ''; $totalServicesCost = 0; for ($i = 0; $i < $selectedServiceLength; $i++) { $selectedItem = $admin->getSingleserviceDetails($selectedService[$i]); $amount = 0; switch ($selectedServiceCarTypes[$i]) { case 1: $amount = $selectedItem['sedan_amount']; break; case 2: $amount = $selectedItem['suv_amount']; break; case 3: $amount = $selectedItem['muv_amount']; break; case 4: $amount = $selectedItem['hb_amount']; break; } $data['selectedItem'] .= '<div class="col-lg-2 col-4 service-box"> <div class="card card-p"> <div class="card-header text-right"> <button type="button" class="no-btn close" aria-label="Close" onclick="removeService(' . $selectedItem['service_id'] . ')"> <span class="close-ico" aria-hidden="true">×</span> </button> </div> <img src="' . $selectedItem['image_name'] . '" class="card-img-top" alt="Product Image"> <div class="card-body"> <h5 class="card-title text-center">' . $selectedItem['name'] . '</h5> <p class="card-text text-center product-price">Rs.' . $amount . ' </p> </div> </div> </div>'; $data['servicesNames'][$i] = $selectedItem['name']; $data['servicesCosts'][$i] = $amount; $data['serviceCarTypes'][$i] = $selectedServiceCarTypes[$i]; $totalServicesCost = array_sum($data['servicesCosts']); } $data['selectedItem'] .= ' <div class="col-lg-2 col-4"> <div class="card card-plus"> <div class="card-body"> <button data-bs-toggle="modal" data-bs-target="#addserivices" class="no-btn splus">+</button> </div> </div> </div>'; $productsTotalCost = 0; for ($i = 0; $i < $selectedProductsLength; $i++) { $selectedProductDetails = $admin->getSingleProductDetails($selectedProducts[$i]); $productCostWithQuantity = $selectedProductDetails['amount'] * $productQuantity[$i]; $data['productsNames'][$i] = $selectedProductDetails['name']; $data['productsCosts'][$i] = $selectedProductDetails['amount'] * $productQuantity[$i]; $data['productsCount'][$i] = $productQuantity[$i]; $productsTotalCost = $productsTotalCost + $productCostWithQuantity; } $data['totalCost'] = $totalServicesCost + $productsTotalCost; echo json_encode($data); } // Coupon Applying if (isset($_POST['coupon'])) { $result = $admin->getSingleCoupon($_POST['coupon']); echo json_encode($result); } // For Admin Payment Submit // For Subadmin Approval Request if (isset($_POST['productPayment'])) { if (isset($_SESSION['admin'])) { $result = $admin->addProductPayment($_POST,1); // Admin Adding } else { $result = $admin->addProductPayment($_POST,2); // SubAdmin Adding } echo json_encode($result); } // For Subadmin Payment if (isset($_POST['subAdminPayment'])) { $result = $admin->subAdminPayment($_POST); // SubAdmin Adding echo $result; } // For Subadmin Allotment Status if (isset($_POST['getStatus'])) { $result = $admin->getAllotmentStatus($_POST); echo json_encode($result); } //get service price based on car types if(isset($_POST['action']) && $_POST['action'] == 'getServicePrice'){ $carType = intval($_POST['carType']); $serviceId = intval($_POST['serviceId']); // Fetch service details from database $service = $admin->getServiceById($serviceId); // Function to fetch service details if ($service) { $amount = 0; $carName = ""; switch ($carType) { case 1: $amount = $service['sedan_amount']; $carName = "Sedan"; break; case 2: $amount = $service['suv_amount']; $carName = "SUV"; break; case 3: $amount = $service['muv_amount']; $carName = "MUV"; break; case 4: $amount = $service['hb_amount']; $carName = "Hatchback"; break; default: echo json_encode(["status" => "error", "message" => "Invalid car type"]); exit; } echo json_encode(["status" => "success", "amount" => $amount, "carName" => $carName]); } else { echo json_encode(["status" => "error", "message" => "Service not found"]); } } ?>