<!DOCTYPE html>
<html lang="en">
<?php include './includes/head.php'; ?>

<body>

    <div id="global-loader">
        <div class="whirly-loader"> </div>
    </div>

    <!-- Main Wrapper -->
    <div class="main-wrapper">

        <?php include './includes/navbar.php'; ?>

        <?php $page = 'customer-list';
        include './includes/sidebar.php'; ?>
        <div class="page-wrapper">
            <div class="content">
                <div class="page-header">
                    <div class="add-item d-flex">
                        <div class="page-title">
                            <h4>New Customer Information</h4>
                            <h6>Create new customer</h6>
                        </div>
                    </div>
                    <ul class="table-top-head">
                        <li>
                            <div class="page-btn">
                                <a href="customer.php" class="btn btn-secondary"><i data-feather="arrow-left" class="me-2"></i>Back to Customer</a>
                            </div>
                        </li>
                        <li>
                            <a data-bs-toggle="tooltip" data-bs-placement="top" title="Collapse" id="collapse-header"><i data-feather="chevron-up" class="feather-chevron-up"></i></a>
                        </li>
                    </ul>

                </div>
                <?php
                require_once 'php/databaseConnection.php';

                // Check if jobNumber is provided
                if (isset($_GET['job_number'])) {
                    $jobNumber = $_GET['job_number'];

                    // Database connection
                    $mysqli = db_connect();
                    if (!$mysqli) {
                        die("Database connection failed: " . $mysqli->connect_error);
                    }

                    // Fetch job card details
                    $stmt = $mysqli->prepare("SELECT 
    job_number, job_date, register_number, year, millage, vehicle_brand, 
    dateTimeIn, dateTimeOut, vehicle_model, vehicle_colour, engine_number, 
    vin_number, purposeAll, fuelBatteryType, powerValue, customer_name, 
    customer_address, contact_number, reported_defects, completed_action, 
    jobCardStatus, contactPerson, personContactNumber, technicianName, 
    supervisor, imageOfCar, customerVAT
FROM customerField
WHERE job_number = ?;
");
                    $stmt->bind_param("s", $jobNumber);
                    $stmt->execute();
                    $result = $stmt->get_result();

                    // Check if record exists
                    if ($result->num_rows > 0) {
                        $jobCard = $result->fetch_assoc();
                    } else {
                        die("No record found for job number: " . htmlspecialchars($jobNumber));
                    }
                    $stmt->close();
                    $mysqli->close();
                } else {
                    die("Job number is required.");
                }
                ?>
                <form action="php/updateCustomer.php?job_number=<?php echo $jobCard['job_number']; ?>" method="post" enctype="multipart/form-data">
                    <?php
                    require_once 'php/databaseConnection.php';

                    $mysqli = db_connect();

                    $result = $mysqli->query("SELECT job_number FROM customerField ORDER BY ID DESC LIMIT 1");
                    $row = $result->fetch_row();

                    if ($row == null) {
                        $total_job_number = 1; // Initialize $total_group_id here for the case where no rows are found
                    } else {
                        $job_number = substr($row[0], 4); // Adjust substring length to skip "FGID"
                        $total_job_number = $job_number + 1; // Increment the numeric part of the group ID
                    }
                    ?>
                    <div class="card">
                        <div class="card-body add-product pb-0">
                            <div class="accordion-card-one accordion" id="accordionExample">
                                <!-- here -->
                                <div class="accordion-item">
                                    <div class="accordion-header" id="headingOne">
                                        <div class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-controls="collapseOne">
                                            <div class="addproduct-icon">
                                                <h5><i data-feather="info" class="add-info"></i><span>Vehicle Information</span></h5>
                                                <a href="javascript:void(0);"><i data-feather="chevron-down" class="chevron-down-add"></i></a>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
                                        <div class="accordion-body">
                                            <div class="row">
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="input-blocks add-product list">
                                                        <label class="form-label">Job Number</label>
                                                        <input type="text" class="form-control" name="jobNumber" value="<?php echo $jobCard['job_number']; ?>" readonly>
                                                        <button type="submit" class="btn btn-primaryadd">
                                                            Generate Code
                                                        </button>
                                                    </div>
                                                </div>
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Job Date</label>
                                                        <input type="date" name="jobDate" class="form-control" value="<?php echo $jobCard['job_date']; ?>">
                                                    </div>
                                                </div>

                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Registration Number</label>
                                                        <input type="text" name="registerNumber" class="form-control" value="<?php echo $jobCard['register_number']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Year</label>
                                                        <input type="text" name="year" class="form-control" value="<?php echo $jobCard['year']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Date/ Time In:</label>
                                                        <input type="text" name="dateTimeIn" class="form-control" value="<?php echo $jobCard['dateTimeIn']; ?>">
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="row">
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Millage</label>
                                                        <input type="text" name="millage" class="form-control" value="<?php echo $jobCard['millage']; ?>">
                                                    </div>
                                                </div>
                                                <div class=" col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Vehicle Brand</label>
                                                        <input type="text" name="vehicleBrand" class="form-control" value="<?php echo $jobCard['vehicle_brand']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Vehicle Model</label>
                                                        <input type="text" name="vehicleModel" class="form-control" value="<?php echo $jobCard['vehicle_model']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Vehicle Colour</label>
                                                        <input type="text" name="vehicleColour" class="form-control" value="<?php echo $jobCard['vehicle_colour']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-2 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Date/ Time Out:</label>
                                                        <input type="text" name="dateTimeOut" class="form-control" value="<?php echo $jobCard['dateTimeOut']; ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Engine/Motor No.</label>
                                                        <input type="text" name="engineNumber" class="form-control" value="<?php echo $jobCard['engine_number']; ?>">
                                                    </div>
                                                </div>
                                                <div class=" col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">VIN No.</label>
                                                        <input type="text" name="vinNumber" class="form-control" value="<?php echo $jobCard['vin_number']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">JobCard Status</label>
                                                        <select class="select" name="jobCardStatus">
                                                            <option>Select</option>
                                                            <option value="Not Opened" <?php if ($jobCard['jobCardStatus'] == 'Not Opened') {
                                                                                            echo 'selected';
                                                                                        } ?>>Not Opened</option>
                                                            <option value="Opened" <?php if ($jobCard['jobCardStatus'] == 'Opened') {
                                                                                        echo 'selected';
                                                                                    } ?>>Opened</option>
                                                            <option value="Closed" <?php if ($jobCard['jobCardStatus'] == 'Closed') {
                                                                                        echo 'selected';
                                                                                    } ?>>Closed</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class=" col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Customer Name</label>
                                                        <input type="text" name="customerName" class="form-control" value="<?php echo $jobCard['customer_name']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Address</label>
                                                        <input type="text" name="customerAddress" class="form-control" value="<?php echo $jobCard['customer_address']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-4 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Contact Number</label>
                                                        <input type="text" name="contactNumber" class="form-control" value="<?php echo $jobCard['contact_number']; ?>">
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- Editor -->
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="input-blocks summer-description-box transfer mb-3">
                                                        <label>Reported Defects/Demanded Repairs</label>
                                                        <textarea class="form-control h-100" name="reportedDefects" rows="5"><?php echo $jobCard['reported_defects']; ?></textarea>
                                                        <p class="mt-1">Maximum 100 Characters</p>
                                                    </div>
                                                </div>
                                                <div class="col-lg-6">
                                                    <div class="input-blocks summer-description-box transfer mb-3">
                                                        <label>Completed Actions</label>
                                                        <textarea class="form-control h-100" name="completedAction" rows="5"><?php echo $jobCard['completed_action']; ?></textarea>
                                                        <p class="mt-1">Maximum 100 Characters</p>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="input-blocks summer-description-box transfer mb-3">
                                                        <label>Pending Reported Defects/Demanded Repairs</label>
                                                        <textarea class="form-control h-100" name="pendingDefects" rows="5"></textarea>
                                                        <p class="mt-1">Maximum 100 Characters</p>
                                                    </div>
                                                </div>
                                                <div class="col-lg-6">
                                                    <div class="input-blocks summer-description-box transfer mb-3">
                                                        <label>Inspection Report</label>
                                                        <textarea class="form-control h-100" name="inspectionReport" rows="5"></textarea>
                                                        <p class="mt-1">Maximum 100 Characters</p>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- /Editor -->

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--/here -->
                            <style>
                                .search-results {
                                    position: absolute;
                                    background: white;
                                    border: 1px solid #ccc;
                                    width: 100%;
                                    max-height: 200px;
                                    overflow-y: auto;
                                    display: none;
                                    z-index: 1000;
                                }

                                .search-results div {
                                    padding: 10px;
                                    cursor: pointer;
                                }

                                .search-results div:hover {
                                    background: #f0f0f0;
                                }
                            </style>
                            <div class="accordion-card-one accordion" id="accordionExample">
                                <div class="accordion-item">
                                    <div class="accordion-header" id="headingOne">
                                        <div class="accordion-button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-controls="collapseOne">
                                            <div class="addproduct-icon">
                                                <h5><i data-feather="info" class="add-info"></i><span>Privacy Information</span></h5>
                                                <a href="javascript:void(0);"><i data-feather="chevron-down" class="chevron-down-add"></i></a>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
                                        <div class="accordion-body">
                                            <div class="row">
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Contact Person</label>
                                                        <input type="text" name="contactPerson" class="form-control" value="<?php echo $jobCard['contactPerson']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Contact Number</label>
                                                        <input type="text" name="personContactNumber" class="form-control" value="<?php echo $jobCard['personContactNumber']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Technician Name</label>
                                                        <input type="text" name="technicianName" class="form-control" value="<?php echo $jobCard['technicianName']; ?>">
                                                    </div>
                                                </div>
                                                <div class="col-lg-3 col-sm-6 col-12">
                                                    <div class="mb-3 add-product">
                                                        <label class="form-label">Supervisor</label>
                                                        <input type="text" name="supervisor" class="form-control" value="<?php echo $jobCard['supervisor']; ?>">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="col-lg-12">
                                <div class="btn-addproduct mb-4">
                                    <button type="button" class="btn btn-cancel me-2">Cancel</button>
                                    <button type="submit" class="btn btn-submit">Save Product</button>
                                </div>
                            </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /Main Wrapper -->
    <div class="customizer-links" id="setdata">
        <ul class="sticky-sidebar">
            <li class="sidebar-icons">
                <a href="#" class="navigation-add" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-original-title="Theme">
                    <i data-feather="settings" class="feather-five"></i>
                </a>
            </li>
        </ul>
    </div>
    <!-- jQuery -->
    <script src="js/jquery-3.7.1.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Feather Icon JS -->
    <script src="js/feather.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Slimscroll JS -->
    <script src="js/jquery.slimscroll.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Datatable JS -->
    <script src="js/jquery.dataTables.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>
    <script src="js/dataTables.bootstrap5.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Bootstrap Core JS -->
    <script src="js/bootstrap.bundle.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Select2 JS -->
    <script src="js/select2.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Datetimepicker JS -->
    <script src="js/moment.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>
    <script src="js/bootstrap-datetimepicker.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Bootstrap Tagsinput JS -->
    <script src="js/bootstrap-tagsinput.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Sweetalert 2 -->
    <script src="js/sweetalert2.all.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>
    <script src="js/sweetalerts.min.js" type="37d26908286f2aa006113b6d-text/javascript"></script>

    <!-- Custom JS -->

    <script src="js/script.js" type="37d26908286f2aa006113b6d-text/javascript"></script>


    <script src="js/rocket-loader.min.js" data-cf-settings="37d26908286f2aa006113b6d-|49" defer=""></script>

    <style>
        .fuel-battery-indicator {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .fuel-battery-indicator input {
            width: 100%;
        }
    </style>

    <!-- Fuel Battery Indicator Ajax -->
    <?php include './includes/fuelBatteryAjax.php'; ?>
    <!-- /Fuel Battery Indicator Ajax -->
</body>


</body>

</html>