<?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);
$text	= "SELECT max(kode_rb) as no_akhir FROM retur_pb WHERE tanggal='$tanggal' ORDER BY kode_rb";
$sql 	= mysql_query($text);
$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++;
	$kode = 'RPB'.sprintf("%02s",$thn).sprintf("%02s",$bln).sprintf("%02s",$tgl).sprintf("%03s",$no_akhir);
	$data['nomor'] = $kode;	
	echo json_encode($data);
}else{
	$data['nomor'] = 'RPB'.sprintf("%02s",$thn).sprintf("%02s",$bln).sprintf("%02s",$tgl).'001';	
	echo json_encode($data);
}
?>