<?php
include "../koneksi.php";
if (isset($_GET['radiokota'])) {
    if ($_GET['radiokota'] == "tangerang") {
        $kota = "TG";
    } elseif ($_GET['radiokota'] == "surabaya") {
        $kota = "SB";
    }
    $idtelp_custraxi = $_GET['idtelp_custraxi'];

}else if(isset($_GET['kota'])){

    if ($_GET['kota'] == "tangerang") {
        $kota = "TG";
    } elseif ($_GET['kota'] == "surabaya") {
        $kota = "SB";
    }
}

$tahun = date('y');
$prefix = "RI-QUO/SV-$kota/$tahun";
$query = mysqli_query($konek, "
                            SELECT nofile_raxips 
                            FROM raxi_ps 
                            WHERE nofile_raxips LIKE '$prefix%' 
                            ORDER BY nofile_raxips DESC 
                            LIMIT 1
                        ");

if (mysqli_num_rows($query) > 0) {
    $row = mysqli_fetch_assoc($query);
    // ambil 3 digit terakhir
    $lastNumber = substr($row['nofile_raxips'], -3);
    $nextNumber = (int)$lastNumber + 1;
} else {
    $nextNumber = 1;
}

$urut = str_pad($nextNumber, 3, '0', STR_PAD_LEFT);
$nofile = "$prefix$urut";

header("Location: ../penawaranraxi-tambah.php?nofile=$nofile&idtelp_custraxi=$idtelp_custraxi");
