<?php
include "../../inc/inc.koneksi.php";

$tanggal= $_POST['tanggal'];
$thn	= substr($tanggal,0,4);
$thn	= $thn-2000;
$bln	= substr($tanggal,5,2);
$tgl	= substr($tanggal,8,2);

$sql 	= mysql_query("SELECT max(kode_bk) as no_akhir FROM jurbk WHERE tanggal='$tanggal' ORDER BY kode_bk");
$row	= mysql_num_rows($sql);

if ($row>0){
	$data=mysql_fetch_array($sql);	
	$no = $data['no_akhir'];
	$no_akhir = (int) substr($no,9,3);
	$no_akhir++;
	$kode = 'BBK'.sprintf("%02s",$thn).sprintf("%02s",$bln).sprintf("%02s",$tgl).sprintf("%03s",$no_akhir);
	$data['nomor'] = $kode;	
	echo json_encode($data);
}else{
	$data['nomor'] = 'BBK'.sprintf("%02s",$thn).sprintf("%02s",$bln).sprintf("%02s",$tgl).'001';
	echo json_encode($data);
}
?>