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

$tgl	= $_POST['tanggal'];
$thn	= substr($tgl,0,4);
$thn1	= (int) $thn-2000;
$bln	= substr($tgl,5,2);
$hari	= substr($tgl,8,2);
$sql 	= mysql_query("SELECT max(kode_opb) as no_akhir FROM sopb WHERE tanggal='$tgl' ORDER BY kode_opb");
$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++;
	$data['nomor']	= 'MB'.sprintf("%02s",$thn1).$bln.$hari.'.'.sprintf("%03s",$no_akhir);
	$data['tanggal']	= $tgl;
	echo json_encode($data);
}else{
	$data['nomor']	= 'MB'.sprintf("%02s",$thn1).$bln.$hari.'.001';
	$data['tanggal']	= $tgl;
	echo json_encode($data);
}
?>