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

$sql 	= mysql_query("SELECT max(kode_ju) as no_akhir FROM jurnalum WHERE year(tanggal)='$thn' AND month(tanggal)='$bln' ORDER BY kode_ju");
$row	= mysql_num_rows($sql);

if ($row>0){	
	$data=mysql_fetch_array($sql);	
	$no = $data['no_akhir'];
	$no_akhir = (int) substr($no, 6, 4);
	$no_akhir++;
	$kode = 'JU'.sprintf("%02s",$thn1).$bln.sprintf("%04s",$no_akhir);
	$data['nomor'] = $kode;
	$data['tanggal'] = $tgl;
	echo json_encode($data);
}else{
	$data['nomor'] = 'JU'.sprintf("%02s",$thn1).$bln.'0001';
	$data['tanggal'] = $tgl;
	echo json_encode($data);
}
?>