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

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

$sql1		= mysql_query("SELECT * FROM interface");
$r1 			= mysql_fetch_assoc($sql1);
$kodelpg	= $r1[kode_lpg];

$sql1	= mysql_query("SELECT * FROM stock WHERE kode_st='$kodelpg' ");
$r1 		= mysql_fetch_assoc($sql1);
$hgbeli	= $r1[hg_beli];

$sql 		= mysql_query("SELECT max(kode_tb) as no_akhir FROM tebus_do WHERE year(tanggal)='$thn' AND month(tanggal)='$bln' ORDER BY kode_tb");
$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++;
	$data['nomor'] = 'TBD'.sprintf("%02s",$thn1).sprintf("%02s",$bln).sprintf("%03s",$no_akhir);
}else{
	$data['nomor'] = 'TBD'.sprintf("%02s",$thn1).sprintf("%02s",$bln).'001';
}

$data['hgbeli'] = $hgbeli;
echo json_encode($data);
?>