<?php
include "../koneksi.php";
if ($_GET['radiokota'] == "tangerang") {
    $kota = "T";
} elseif ($_GET['radiokota'] == "surabaya") {
    $kota = "S";
}
$idtelp_custbisman = $_GET['idtelp_custbisman'];

$tahun = date('y');
$prefix = "PNW-SVC.BBB-$kota.$tahun";
$query = mysqli_query($konek, "
                            SELECT nofile_bismanps 
                            FROM bisman_ps 
                            WHERE nofile_bismanps LIKE '$prefix%' 
                            ORDER BY nofile_bismanps DESC 
                            LIMIT 1
                        ");

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

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

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