<?php


if (isset($_GET[e])){
	if ($_GET[e] == "add"){
		$cek1 = getFromTable("select count(id) from tbl_pos_out");
		$cek2 = str_pad(((int) $cek1 + 1), 3, "0", STR_PAD_LEFT);
		$id = $cek1 + 1;
		$tgl = date("d");
		$bln = date("m");

		$kd = "TRS-".$bln.$tgl.$cek2;

		mysql_query("insert into tbl_pos_out (id, no_meja, tgl_trans, waktu, no_id, user_input, jns_trans) 
		values ($id, '".$_GET[no_meja]."', CURRENT_DATE, CURRENT_TIME, '$kd', '".$_SESSION[nama_usr]."', '".$_GET[kd]."') ");
		
		echo "<script language='JavaScript'>document.location='index2.php?p=".$_GET[p]."&jns=".$_GET[jns]."&kd=".$_GET[kd]."&act=".$_GET[act]."&e=tambah&t=$kd'</script>";
	} elseif ($_GET[e] == "tambah") {
	$r = mysql_query("select * from tbl_pos_out where no_id = '".$_GET[t]."'");
	$n = mysql_num_rows($r);
	if($n > 0) $d = mysql_fetch_object($r);
	mysql_free_result($r);
	if ($d->no_booking == NULL){
		$ket = "Individual";
	} else {
		$ket = "di Tangguhkan ke ".$d->no_booking ;
	}
		?>
		<div class="column">
		<div class="ui top attached info message">Data Customer</div>
		<div class="ui bottom attached segment">
		<table width="100%" border="1px" class="gridtable_keterangan">
			<tr>
				<td width="8%"><b>Trans No.</b></td>
				<td width="12%">: <?php echo $_GET[t]; ?></td>
				
				<td width="8%"><b>Table No.</b></td>
				<td width="10%">: <?php echo $d->no_meja; ?></td>
				
				<td width="8%"><b>Trans Date</b></td>
				<td width="12%">: <?php echo $d->tgl_trans; ?></td>
				
				<td width="8%"><b>Trans Time</b></td>
				<td width="10%">: <?php echo $d->waktu; ?></td>
				
				<td width="10%"><b>Bill Status</b></td>
				<td width="14%">: <?php echo $ket; ?></td>
			</tr>
		</table>
		</div>
		</div>
		<?php
		include("input_layanan_out.php");
		
	} else {
		
	}

} else {
	title("<img src='images/sales-report-icon.png' width='65' align='absmiddle' >  Input Data  (".$_GET[jns].")");
?>
<div class="ui three column stackable grid">
	<div class="column">
		<form>
		<input type="hidden" name="p" value="<?php echo $PID;?>"/>
		<input type="hidden" name="jns" value="<?php echo $_GET[jns];?>"/>
		<input type="hidden" name="kd" value="<?php echo $_GET[kd];?>"/>
		<input type="hidden" name="act" value="<?php echo $_GET[act];?>"/>
		<input type="hidden" name="e" value="add"/>
		<table width="100%" class="gridtable_form" border="1px">					
			<tr>
				<td>Guest Name.</td>
				<td><input type="text" name="no_meja" value="" required="required"></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" value="Save" class="blue ui mini button" ></td>
			</tr>
		</table>
		</form>		
	</div>	
</div>

<form>
<input type="hidden" name="p" value="<?php echo $PID; ?>"/>
<input type="submit" style="display: none;"/>
<table id='mytable' class="gridtable tableWithFloatingHeader" width="100%" border="1px">
	<tr>
		<td class="gridtable_th" align="center">No</td>
		<td class="gridtable_th" align="center">Trans Date</td>
		<td class="gridtable_th" align="center">Trans No</td>
		<td class="gridtable_th" align="center">Table No</td>
		<td class="gridtable_th" align="center">Bill Status</td>
		<td class="gridtable_th" align="center">Guest ID</td>
	</tr>
	<tr>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th">&nbsp;</td>
		<td class="gridtable_th" align="center"><input type="text" size="10" name="no_trans" value="<?php echo $_GET[no_trans];?>"></td>
		<td class="gridtable_th" align="center"><input type="text" size="5" name="no_meja" value="<?php echo $_GET[no_meja];?>"></td>
		<td class="gridtable_th">&nbsp;</td>		
		<td class="gridtable_th" align="center"><input type="text" size="10" name="no_booking" value="<?php echo $_GET[no_booking];?>"></td>		
	</tr>
<?php
$sql = "select * from tbl_pos_out where status_bayar = 'N' and jns_trans = '".$_GET[kd]."' ";
$r = mysql_query($sql);
$n = mysql_num_rows($r);
$no = 1;
while ($row = mysql_fetch_array($r)) { 
	if ($row[no_booking] == NULL){
		$stat = "Individual";
	} else {
		$stat = "di Tagihkan";
	}
?>
	<tr>
		<td class="gridtable_td"><?php echo $no++; ?></td>
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[tgl_trans])); ?></td>
		<td class="gridtable_td" align="center"><a href="<?php echo "$SC?p=$PID&jns=".$_GET[jns]."&kd=".$_GET[kd]."&act=pos_out&e=tambah&t=$row[no_id]";?>"><?php echo $row[no_id]; ?></a></td>		
		<td class="gridtable_td" align="center"><?php echo ucwords(strtolower($row[no_meja])); ?></td>
		<td class="gridtable_td"><a href="<?php echo "javascript: UpdateStat('$row[no_id]','$row[no_booking]')";?>"><img src="images/Service-icon.png" width="16"/></a>&nbsp;&nbsp;<?php echo ucwords(strtolower($stat)); ?></td>
		<td class="gridtable_td"><?php echo ucwords(strtolower($row[no_booking])); ?></td>
	</tr>
	<?php } ?>
</table>
</form>
<script language='JavaScript'>
function UpdateStat(tag1,tag2) {
    sWin = window.open('includes/update_stat.php?idx='+tag1+'&no_booking='+tag2, 'xWin',
 'top=0,left=0,width=950,height=550,menubar=no,scrollbars=yes');
    sWin.focus();
}
</script>
<?php } ?>