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

$tanggal= $_POST[tanggal];
$shift	= $_POST[shift];
$kodetl	= $_POST[kodetl];
$thn	= substr($tanggal,0,4);
$bln	= substr($tanggal,5,2);
$tgl	= substr($tanggal,8,2);
$thn1	= (int) $thn-2000;
$kode  	= 'SB'.sprintf("%02s",$thn1).$bln.$tgl.$shift.$kodetl;
$data['nomor'] = $kode;

$text	= "SELECT * FROM setor_bbm WHERE kode_sb='$kode' AND batal='' GROUP BY kode_sb";
$sql 	= mysql_query($text);
$row	= mysql_num_rows($sql);
if ($row>0){
	while ($r=mysql_fetch_array($sql)){	
		$data['kodesb'] = $r['kode_sb'];
	}
	echo json_encode($data);
}else{
	$data['kodesb'] = '';
	echo json_encode($data);
}
?>