<?php
include "../../inc/inc.koneksi.php";
$tanggal= $_POST['tanggal'];
$shift  = $_POST['shift'];
$thn	= substr($tanggal,0,4);
$bln	= substr($tanggal,5,2);
$tgl	= substr($tanggal,8,2);
$thn1	= (int) $thn-2000;

$sql 	= mysql_query("SELECT max(kode_kk) as no_akhir FROM jurkk WHERE tanggal='$tanggal' AND shift='$shift' ORDER BY kode_kk");
$row	= mysql_num_rows($sql);

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