<?php
include 'connection.php';

if (isset($_POST['dealer_code']) && isset($_POST['name_dealer']) && isset($_POST['bulan']) && isset($_POST['tahun'])) {
    $dealer_code = $_POST['dealer_code'];
    $name_dealer = $_POST['name_dealer'];
    $bulan = $_POST['bulan'];
    $tahun = $_POST['tahun'];

    $query = "SELECT *
              FROM target_service_dealer
              WHERE site_id = '$dealer_code' AND name_dealer = '$name_dealer' AND bulan = '$bulan' AND tahun = '$tahun'";

    $result = $conn->query($query);

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        echo "
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Nama Dealer</label>
              <div class='col-sm-9'>
                <input type='text' class='form-control' placeholder='name_dealer' value='{$row['name_dealer']}' aria-describedby='basic-addon1' disabled>
              </div>
            </div>
            
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Bulan</label>
              <div class='col-sm-9'>
                <input type='text' class='form-control' placeholder='bulan' value='{$row['bulan']}' aria-describedby='basic-addon1' disabled>
              </div>
            </div>
            
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Tahun</label>
              <div class='col-sm-9'>
                <input type='text' class='form-control' placeholder='tahun' value='{$row['tahun']}' aria-describedby='basic-addon1' disabled>
              </div>
            </div>
            
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>RUT</label>
              <div class='col-sm-9'>
                  <input type='text' class='form-control' placeholder='rut' value='" . number_format($row['rut'], 0, ',', '.') . "' aria-describedby='basic-addon1' disabled>
              </div>
            </div>

            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Target Jasa</label>
              <div class='col-sm-9'>
                <div class='input-group'>
                  <span class='input-group-text'>Rp</span>
                  <input type='text' class='form-control' placeholder='total_jasa' value='" . number_format($row['total_jasa'], 0, ',', '.') . "' aria-describedby='basic-addon1' disabled>
                </div>
              </div>
            </div>
            
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Part dan Oli</label>
              <div class='col-sm-9'>
                <div class='input-group'>
                  <span class='input-group-text'>Rp</span>
                  <input type='text' class='form-control' placeholder='part_n_oli' value='" . number_format($row['part_n_oli'], 0, ',', '.') . "' aria-describedby='basic-addon1' disabled>
                </div>
              </div>
            </div>
            
            <div class='row mb-3'>
              <label class='col-sm-3 col-form-label'>Teknisi</label>
              <div class='col-sm-9'>
                  <input type='text' class='form-control' placeholder='jml_tech' value='" . number_format($row['jml_tech'], 0, ',', '.') . "' aria-describedby='basic-addon1' disabled>
              </div>
            </div>
        ";
    } else {
        echo "<p>Data not found for the selected dealer and period.</p>";
    }
} else {
    echo "<p>Invalid parameters.</p>";
}
?>
