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

$tanggal= $_POST[tanggal];
$thn	= substr($tanggal,0,4);
$bln	= substr($tanggal,5,2);
$thn1	= (int) $thn-2000;

$sql 	= mysql_query("SELECT max(kode_do) as no_akhir FROM stock_do WHERE year(tanggal)='$thn' AND month(tanggal)='$bln' ORDER BY kode_do");
$row	= mysql_num_rows($sql);
if ($row>0){
	$data=mysql_fetch_array($sql);	
	$no = $data['no_akhir'];
	$no_akhir = (int) substr($no, 6, 5);
	$no_akhir++;
	$kode = 'DO'.sprintf("%02s",$thn1).$bln.sprintf("%03s",$no_akhir);
	$data['nomor'] = $kode;
	echo json_encode($data);
}else{
	$data['nomor'] = 'DO'.sprintf("%02s",$thn1).$bln.'001';
	echo json_encode($data);
}
?>