<?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_sj) as no_akhir FROM surat_jln WHERE tanggal='$tanggal' ORDER BY kode_sj");
$row		= mysql_num_rows($sql);

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