<?php
include "../../inc/inc.koneksi.php";
$kodegr	= $_POST[kode];
$text	= "SELECT max(kode_st) as no_akhir FROM stock WHERE kode_gr='$kodegr' ORDER BY kode_st ";
$sql 	= mysql_query($text);
$row	= mysql_num_rows($sql);

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