<?php
include "../../inc/inc.koneksi.php";
$tgl	= $_POST['tanggal'];
$thn	= substr($tgl,0,4);
$thn1	= (int) $thn-2000;
$text	= "SELECT max(kode_bk) as no_akhir FROM jurbk WHERE year(tanggal)='$thn' ORDER BY kode_bk";
$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, 4, 5);
	$no_akhir++;
	$kode = 'BK'.sprintf("%02s",$thn1).sprintf("%05s",$no_akhir);
	$data['nomor'] = $kode;
	$data['tanggal'] = $tgl;
	echo json_encode($data);
}else{
	$data['nomor'] = 'BK'.sprintf("%02s",$thn1).'00001';
	$data['tanggal'] = $tgl;
	echo json_encode($data);
}
?>