<?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_ppi) as no_akhir FROM jurppi WHERE year(tanggal)='$thn' AND month(tanggal)='$bln' ORDER BY kode_ppi");
$row	= mysql_num_rows($sql);

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