<?php 
require_once("config/koneksi2.php");
function kd_transaksi() {
	$kode_temp = fetch_row("SELECT kode_transaksi FROM bs_order ORDER BY kode_transaksi DESC LIMIT 0,1");
	if ($kode_temp == '')
		$kode = "T0000000001";
	else {
		$jum = substr($kode_temp, 1, 11);
		$jum++;
		if ($jum <= 9)
			$kode = "T000000000" . $jum;
		elseif ($jum <= 99)
			$kode = "T00000000" . $jum;
		elseif ($jum <= 999)
			$kode = "T0000000" . $jum;
		elseif ($jum <= 9999)
			$kode = "T000000" . $jum;
		elseif ($jum <= 99999)
			$kode = "T00000" . $jum;
		elseif ($jum <= 999999)
			$kode = "T00000" . $jum;
		elseif ($jum <= 9999999)
			$kode = "T0000" . $jum;
		elseif ($jum <= 99999999)
			$kode = "T000" . $jum;
		elseif ($jum <= 999999999)
			$kode = "T00" . $jum;
		elseif ($jum <= 9999999999)
			$kode = "T0" . $jum;
		elseif ($jum <= 99999999999)
			$kode = "T" . $jum;
		else
			die("Kode pemesanan melebihi batas");
	}
	return $kode;
	echo $kode_temp;
}

function getLastTrans() { 
$querycount="SELECT MAX(ID) AS LastID FROM bs_order"; 
$result=mysql_query($querycount) or die(mysql_error()); 
$row=mysql_fetch_array($result, MYSQL_ASSOC); 
return $row['LastID']; 
}
$LastID=getLastTrans();

function FormatNoTrans($num) { 
$num=$num+1; switch (strlen($num)) {     
/*case 1 : $NoTrans = "00000000".$num; break;     
case 2 : $NoTrans = "0000000".$num; break;     
case 3 : $NoTrans = "000000".$num; break;     
case 4 : $NoTrans = "00000".$num; break;*/
case 1 : $NoTrans = "0000".$num; break;   
case 2 : $NoTrans = "000".$num; break;   
case 3 : $NoTrans = "00".$num; break;   
case 4 : $NoTrans = "0".$num; break;        
default: $NoTrans = $num;        
}           
return $NoTrans; }

$LastID=FormatNoTrans(getLastTrans());
$LastIDa="BS-".FormatNoTrans(getLastTrans()); //Untuk kombinasi dengan huruf 
//$LastID=year("Y").FormatNoTrans(getLastTrans()); //Untuk kombinasi dengan tahun
//echo $LastIDa;

	


?>