<?php
include "../../inc/inc.koneksi.php";
$kode	= $_POST[kode];

$text	= "SELECT max(id_bon) as no_akhir FROM setor_bbm WHERE kode_sb='$kode' ORDER BY kode_sb";
$sql 	= mysql_query($text);
$row	= mysql_num_rows($sql);

if ($row>0){	
	$data=mysql_fetch_array($sql);	
	$no = $data['no_akhir'];
	$no_akhir = (int) substr($no, 0, 3);
	$no_akhir++;
	$idbon= sprintf("%03s",$no_akhir);
	$data['nomor'] = $idbon;
	echo json_encode($data);
}else{
	$data['nomor'] = '001';
	echo json_encode($data);
}
?>