<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>
		RASIO - POS
	</title>
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl ?>/assets/thema/posr/css/pos.css?ver=<?php echo date("ymdHis") ?>">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl ?>/assets/thema/posr/css/pos_theme_black.css">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl ?>/assets/thema/posr/css/pos_mobile.css">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl ?>/assets/css/flexigrid/flexigrid.css">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->baseUrl ?>/assets/css/jquery.apank.popUp.css">
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/jquery-1.7.2.min.js" ></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/jquery-ui-1.8.19.custom.min.js" ></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/jquery.shortcuts.min.js" ></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/apank.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/jquery.meio.mask.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/accounting.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/md5.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/thema/posr/js/pos.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/flexigrid.js"></script>
	<script type="text/javascript" src="<?php echo $this->baseUrl ?>assets/js/md5.js"></script>
</head>
<body>
<div id="apankForm"></div>
	<div id="content">
		<table id="_tabContent" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<!-- Tab Meja -->
				<td id="_tabContentL">
				    <!-- Menu Atas -->
					<div class="_hedAtas">
						<input class="_menu _back" type="button" value="B A C K" onclick="location.href='<?php echo $this->baseUrl ?>application/index/MIS';">
						M E J A
					</div>
					<!-- Pilih Lantai -->
					<div class="_dataKat">
						<?php
						$lt = $this->em->getFindBy("kat", "*", array('jenis = 2'), "kd_kat");
						$def_lt = $lt[0];
						foreach($lt as $r){
						?>
						<input type="button" class="_iconLantai _menu" kode="<?php echo str_ireplace(' ','_',$r->kd_kat) ?>" value="<?php echo $r->nm_kat ?>">
						<?php } ?>
					</div>
					<!-- Pilih Meja -->
					<div>
						<?php foreach($lt as $r){ ?>
							<table class="_dataMejaDet" id="_dataMejaDet_<?php echo str_ireplace(' ','_',$r->kd_kat) ?>" style="display: none">
								<tr class="_dataMejaDetHed">
									<td>
										Daftar Meja <?php echo $r->nm_kat ?>
									</td>
								</tr>
								<tr>
									<td>
										<?php
										$meja = $this->em->getFindBy("merek", "*", array("kd_kat = '".$r->kd_kat."'"), "kd_merek");
										if(empty($def_meja)) $def_meja = $meja[0];
                                                 
                                        foreach($meja as $r){
										?>
										<input type="button" class="_iconMeja _menu" id="_iconMeja_<?php echo $r->kd_merek ?>" kode="<?php echo $r->kd_merek ?>" value="<?php echo $r->nm_merek ?>">
										<?php } ?>
									</td>
								</tr>
							</table>
						<?php } ?>
					</div>
				</td>
				
				<!-- Tab Menu & Print Ulang -->
				<td id="_tabContentC">
				    <!-- Menu Atas -->
					<div class="_hedAtas">
						M E N U (<span id='_time'><?php echo date("d/m/Y H:i") ?></span>)
						<div class="_petugas">
							Petugas
							<select class="_petugasSelect" style="width: 150px;">
								<?php 
								$petugas = $this->em->getFindBy("sub", "*", array("jenis = '1'", "aktif = 'AKTIF'", "(jabatan = 'KASIR' or kd_sub = 'TESA')", "kd_sub != 'ARTHUR'"), "nm_sub");
								foreach ($petugas as $n) { 
								?>
									<option value="<?php echo $n->kd_sub ?>"><?php echo $n->nm_sub ?></option>
								<?php } ?>
							</select>
						</div>
					</div>
					<!-- Pilih Kategori Produk & Operasi -->
					<div class="_dataKat">
						<!-- Button Print, Approve, & Pindah Meja -->
						<div style="text-align: right;">
							<!--<input type="button" class="_btnPrint" kode="cam" value="PRINT BAR (CAMILAN)" style="display: none">-->
							<input type="button" class="_btnPrint" kode="bar" value="PRINT BAR">
							<input type="button" class="_btnPrint" kode="dapur" value="PRINT DAPUR">
							<input type="button" class="_btnPrint" kode="checker" value="PRINT CHECKER">
							<!--<input type="button" class="_btnPrint" kode="all2" value="PRINT ALL" style="display: none">-->
							<input type="button" class="_btnPrint" kode="bill" value="PRINT BILL"><br>
							
							<?php
    						$kat = $this->em->getFindBy("kat", "*", array('jenis = 1'), "urut");
    						if(empty($def_kat)) $def_kat = $kat[0];
    						foreach($kat as $r){
    						?>
    							<input type="button" style='float:left' class="_iconKat _menu" kode="<?php echo str_ireplace(' ','_',$r->kd_kat) ?>" value="<?php echo $r->nm_kat ?>">
    						<?php } ?>
							
							<input type="button" class="_btnPindah _menu" value="PINDAH MEJA">
							<!--<input type="button" class="_btnShowPrint _menu" id="_btn_show_print" value="SHOW PRINT">-->
							<!--<input type="button" class="_btnReset _menu" value="RESET PRINT">-->
							<input type="button" class="_btnAccept _menu" id="_btn_approve" value="APPROVE">
						</div>
					</div>
					<!-- Pilih Sub Kategori Produk -->
					<div class="_dataMenu">
						<div>
							<?php 
								$skats = array();
								foreach($kat as $r){ 
							?>
								<table class="_dataSKat" id="_dataSKat_<?php echo str_ireplace(' ','_',$r->kd_kat) ?>" style="display: none">
									<tr>
										<td>
											<?php
												$skat = $this->em->getFindBy("skat", "*", array("kd_kat = '".$r->kd_kat."'"), "kd_skat");
												if(empty($def_skat)) $def_skat = $skat[0];
                                				foreach($skat as $r){
												$skats[] = $r;
											?>
												<input type="button" class="_iconSKat _menu" kode="<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" value="<?php echo $r->nm_skat ?>">
											<?php } ?>
										</td>
									</tr>
								</table>
							<?php } ?>
						</div>
					</div>
					<div style="margin-top: 0px">&nbsp;</div>
					<!-- Pilih Produk -->
					<div class="_dataMenuItem">
						<?php
						foreach($skats as $r){
						?>
						<table class="_dataMenuDet" id="_dataMenuDet_<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" style="display: none">
							<tr class="_dataMejaDetHed" style="position: sticky; top:0;">
								<td>
									Daftar Menu <?php echo $r->nm_skat ?>
								</td>
							</tr>
							<tr style="position: sticky; top:30px;">
								<td>
									<input type="text" kode="<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" id="_menuSearch_<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" class="_menuSearch" placeholder="Search...">
									<input type="button" kode="<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" class="_clearSearch" value="X">
								</td>
							</tr>
							<tr>
								<td>
									<?php
										$menu = $this->em->getFindBy("inv", "*", array("kd_skat = '".$r->kd_skat."'","aktif='T'"), "nm_inv");
										foreach($menu as $r2){
											$note = $this->em->getFindBy("note", "*", array("kd_inv = '".$r2->kd_inv."'"), "kdnote");
									?>
										<div class="_iconMenu _iconMenu_<?php echo str_ireplace(' ','_',$r->kd_skat) ?>" nama="<?php echo $r2->nm_inv ?>">
                                            <img src="<?php echo $this->baseUrl.'assets/upload/'.$r2->file ?>" class="_menuItemImg">
                                            <div class="_menuItemName">
                                                <?php echo $r2->nm_inv ?>
                                            </div>
                                            <div class="_menuItemPrice">
                                                Rp. <?php echo number_format($r2->harga_jual) ?>
                                            </div>
                                            <div>
                                                <input type="button" kode="<?php echo $r2->kd_inv ?>" class="_btnPlusMin" value="-">
                                                <input type="number" id="qty_<?php echo $r2->kd_inv ?>" class="_qtyItem" value="1" min="1" max="99">
                                                <input type="button" kode="<?php echo $r2->kd_inv ?>" class="_btnPlusMin" value="+">
                                            </div>
                                            <div class="_menuItemNote">
                                                <select class="_noteSelect _menuItemNoteSelect" kode="<?php echo $r2->kd_inv ?>" id="note_<?php echo $r2->kd_inv ?>">
                                                    <?php 
                                                        if(!empty($note)){ 
                                                            echo '<option value="choose note">CHOOSE NOTE</option>'; 
                                                        }
                                                        foreach ($note as $n) { 
                                                    ?>
                                                        <option value="<?php echo $n->nmnote ?>"><?php echo $n->nmnote ?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <!--<div class="_menuItemTambahan">
												<input type="button" kode="<?php echo $r2->kd_inv ?>" class="_btnTambahan" style="width: 150px;" value="Tambahan?">
											</div>-->
                                            <div class="_menuItemKet">
                                                <textarea class="ket_item _menuItemKetArea" id="ket_<?php echo $r2->kd_inv ?>"></textarea>
                                            </div>
                                            <div class="_menuItemTambah">
                                                <input type="button" value="TAMBAH" kode="<?php echo $r2->kd_inv ?>" class="_btnTambah">
                                            </div>
                                        </div>
									<?php } ?>
								</td>
							</tr>
						</table>
						<?php } ?>
					</div>
				</td>
				
				<!-- Tab Bill -->
				<td id="_tabContentR">
					<div class="_hedAtas">
						B I L L
					</div>
					<div class="_dataBill" id="_dataBill"></div>
				</td>
			</tr>
		</table>
	</div>
</body>
</html>

<form id="postItem">
<input type="hidden" id="item_ket" name="item_ket">
<input type="hidden" id="item_qty" name="item_qty">
<input type="hidden" id="item_meja" name="item_meja">
<input type="hidden" id="item_kd_inv" name="item_kd_inv">
</form>
<form id="postItemDelete">
<input type="hidden" id="no_item" name="no_item">
</form>
<?php
$kategori = $kat[0];
?>
<div id="errorDisplay"></div>
<input type="hidden" id="baseUrl" value="<?php echo $this->baseUrl ?>">
<input type="hidden" id="kodemeja">
<input type="hidden" id="pembeli">
<input type="hidden" id="pindahmeja" value="F">
<input type="hidden" id="prosesStatus" value="">
<input type="hidden" id="modeT" value="">
<input type="hidden" id="noEks" value="">
<input type="hidden" id="total">

<!-- Dialog -->
<div id="_dialogPindahMeja" style="display:none;">
	<label>Pilih meja baru:</label>
	<select id="_pilihMeja">
		
	</select>
</div>
<div id="_dialogBatal" style="display: none;">
    <input type="hidden" id="_no_item">
    Tuliskan alasan hapus:<br>
    <input type="text" id="_ket"><br><br>
    Masukkan username supervisor:<br>
    <input type="text" id="_user"><br><br>
    Masukkan password supervisor:<br>
    <input type="password" id="_pass">
</div>

<script type="text/javascript">
$(document).ready(function(){
	setDec();
	$('.meioMask').setMask();

    /* Tab Left */
    // Load Meja
    _makeLoadMeja = false;
	makeLoadMeja = function(_kode){
		if(_makeLoadMeja != false){
			_makeLoadMeja.abort();
		}
		$('#_dataBill').html('Loading...');
		$('._btnTambah').attr('disabled', true);
		_makeLoadMeja = $.ajax({
			url: $('#baseUrl').val()+'posr/loadBill/&kode='+_kode,
			type : 'POST',
			data : $('form').serialize(),
			success: function(data){
				$('#_dataBill').html(data);
			}
		});
	}
	$('._iconLantai').click(function(){
		_kode = $(this).attr('kode');
		$('._dataMejaDet').removeAttr('style');
		$('._dataMejaDet').css('display', 'none');
		$('#_dataMejaDet_'+_kode).removeAttr('style');
	})
	$("#_dataMejaDet_<?php echo $def_lt->kd_kat ?>").removeAttr('style');
	$('._iconMeja').click(function(){
		_kode = $(this).attr('kode');
		makeLoadMeja(_kode);
	})
	$('._iconMeja').removeClass('_mejaAktif');
	<?php foreach($this->data->aktif as $meja){ ?>
		$('#_iconMeja_<?php echo $meja ?>').addClass("_mejaAktif");
	<?php } ?>
	makeLoadMeja("<?php echo $def_meja->kd_merek ?>");
	
	/* Tab Center */
    //Pilih Menu Produk
    $('._iconKat').click(function(){
		_kode = $(this).attr('kode');
		$('._dataSKat').removeAttr('style');
		$('._dataSKat').css('display', 'none');
		$('#_dataSKat_'+_kode).removeAttr('style');
	})
    $("#_dataSKat_<?php echo $def_kat->kd_kat ?>").removeAttr('style');
	$('._iconSKat, #_btn_bayar').click(function(){
		_kode = $(this).attr('kode');
		$('._dataMenuDet').removeAttr('style');
		$('._dataMenuDet').css('display', 'none');
		$('#_dataMenuDet_'+_kode).removeAttr('style');
	})
    $("#_dataMenuDet_<?php echo $def_skat->kd_skat ?>").removeAttr('style');
	$('._menuSearch').on('input', function() {
		_kode = $(this).attr('kode');
		$('._iconMenu_'+_kode).removeAttr('style');
		$('._iconMenu_'+_kode).css('display', 'none');
		_searchValue = $(this).val().toLowerCase();
		if(_searchValue == "") {
			$('._iconMenu_'+_kode).removeAttr('style');
		}
		else{
			_menus = $('._iconMenu_'+_kode);
			_menus.each(function() {
                _menu = $(this);
                _txt = _menu.attr('nama').toLowerCase();
                
                if (_txt.includes(_searchValue)) {
                    _menu.removeAttr('style');
                }
            });
		}
	})
	$('._noteSelect').on('click', function() {
		_kode = $(this).attr('kode');
		_note = $(this).find(":selected").val()
		if(_note.toLowerCase() != "choose note"){
			const _currentNote = $('#ket_' + _kode).val();
			$('#ket_' + _kode).val(_currentNote ? _currentNote + ', ' + _note.toLowerCase() : _note.toLowerCase());
			$(this)[0].selectedIndex = 0;
		}
	})
	$('._btnTambahan').on('click', function() {
		_kode = $(this).attr('kode');
		$('#ket_' + _kode).val("tambahan");
	})
	$('._clearSearch').click(function() {
		_kode = $(this).attr('kode');
		$('#_menuSearch_'+_kode).val("");
		$('#_menuSearch_'+_kode).trigger('input');
	})
	$('._btnPlusMin').click(function(){
		_kode = $(this).attr('kode');
		_val = $(this).val();
		_qty = $('#qty_'+_kode).val();
		_qty = parseInt(_qty);
		if(_val === '+'){
			_qty = _qty + 1;
		}
		if(_val === '-'){
			_qty = _qty - 1;
		}
		if(_qty < 1) _qty = 1;
        if(_qty > 99) _qty = 99;
		$('#qty_'+_kode).val(_qty);
	})
	$('._qtyItem').on('input', function(){
        _val = parseInt($(this).val());
    
        //if(isNaN(_val)) _val = 1;
        if(_val < 1) _val = 1;
        if(_val > 99) _val = 99;
    
        $(this).val(_val);
    });
	_makeSimpanItem = false;
	makeSimpanItem = function(_inv, _qty, _ket){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		if(_makeSimpanItem != false){
			_makeSimpanItem.abort();
		}
		$('._btnTambah').attr('disabled', true);
		$('#_dataBill').html('Loading...');
		
		$('#item_kd_inv').val(_inv);
		$('#item_qty').val(_qty);
		$('#item_meja').val(_meja);
		$('#item_ket').val(_ket);
		
		_makeSimpanItem = $.ajax({
			url: $('#baseUrl').val()+'posr/tambahItem/&kode='+_meja+'&inv='+_inv+'&qty='+_qty+'&kd_kasir='+$("._petugasSelect").val(),
			type : 'POST',
			data : $('#postItem').serialize(),
			success: function(data){
				$('#_dataBill').html(data);
			}
		});
	}
	$('._btnTambah').click(function(){
		_kode = $(this).attr('kode');
		_val = $(this).val();
		_ket = $('#ket_'+_kode).val();
		_qty = $('#qty_'+_kode).val();
		_qty = parseInt(_qty);
		if(_qty == 0 || isNaN(_qty)){
			alert('Qty 0');
		}else if(_qty < 0){
			conf = confirm("Yakin Qty Minus?");
			if(conf){
				makeSimpanItem(_kode, _qty, _ket);
			}
		}else{
			makeSimpanItem(_kode, _qty, _ket);
		}
	})
	
	// Approve Bill
	_makeAppPending = false;
	makeAppPending = function(){
		if(_makeAppPending != false){
			_makeAppPending.abort();
		}
		$('#_dataBill').html('Loading...');
		$('._btnTambah').attr('disabled', true);
		url = $('#baseUrl').val()+'posr/appBill/&kode='+$('#kodemeja').val()+'&kd_kasir='+$("._petugasSelect").val()
		pembeli = $('#pembeli').val()
		if(pembeli != ""){
			url += '&pembeli='+pembeli
		}
		_makeAppPending = $.ajax({
			url: url,
			type : 'POST',
			data : $('form').serialize(),
			success: function(data){
				$('#_dataBill').html(data);
				printAllBill(["checker","bar","dapur"],'T', 'F', 'T'); //
			}
		});
	}
	$('#_btn_approve').click(function(){
		_conf = confirm("Yakin Aprove Pesanan?");
		if(_conf){
			makeAppPending();
		}
	})
	
	// Print
	$('#_btn_show_print').click(function() {
		printButton = $('._btnPrint');
		
		if (printButton.is(':visible')) {
			printButton.hide();
			$(this).val('SHOW PRINT');
		} else {
			printButton.show();
			$(this).val('HIDE PRINT');
		}
	});
	hidePrint = function(){
		printButton = $('._btnPrint');
		printButton.hide();
		$('#_btn_show_print').val('SHOW PRINT');
	}
	$('._btnPrint').click(function(){
		_conf = confirm("Print Nota?");
		if(_conf){
			_kode = $(this).attr('kode');
			if(_kode == "all2"){
				printAllBill(["checker","dapur","bar"], 'F', 'F', 'F');
			}
			else {
				//if(_kode == "checker"){ printBill(_kode, 'T', 'T');}
				//else{ }
				printBill(_kode, 'F', 'F', 'F');
			}
		}
	})
	_printBill = false;
	printBill = function(_mode, _flag = 'T', _copy = 'T', _app = 'F', _manual = 'F'){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		if(_printBill != false){
			_printBill.abort();
		}
    	_diskg = $('#_diskg').val().replace(/,/g, '');
    	_ppn = $('#_ppn').val();
		
		if(_manual == 'T'){
		    _printBill = $.ajax({
    			url: $('#baseUrl').val()+'posr/printBill/&kode='+_meja+'&mode='+_mode+'&flag='+_flag+'&copy='+_copy+'&app='+_app+'&diskg='+_diskg+'&ppn='+_ppn,
    			type : 'POST',
    			data : $('#postItem').serialize(),
    			success: function(data){
    				if(data == null) data = '';
    				printWindow = window.open('about:blank', 'Print Bill', 'height=600,width=800');
    				printWindow.document.write(data);
    				printWindow.document.close();
    				//hidePrint();
    			}
    		});
		}
		else{
		    _printBill = $.ajax({
    			url: $('#baseUrl').val()+'posr/makePrint/&kode='+_meja+'&mode='+_mode+'&flag='+_flag+'&copy='+_copy+'&app='+_app+'&diskg='+_diskg+'&ppn='+_ppn,
    			type : 'POST',
    			data : $('#postItem').serialize(),
    			success: function(data){
    			    $('#_dataBill').append(data);
    			}
    		});
		}
	}
	printAllBill = function(_modes = [], _flag = 'T', _copy = 'F', _app = 'F', _manual = 'F') {
	  _meja = $('#kodemeja').val();
	  if (_meja === '') {
		alert('Pilih Meja Terlebih Dahulu!');
		return;
	  }

	  const delay = 1000;
	  _modes.forEach(function(_mode, index) {
		setTimeout(function() {
		  	if(_manual == 'T'){
    		    $.ajax({
    				url: $('#baseUrl').val() + 'posr/printBill/&kode='+_meja+'&mode='+_mode+'&flag='+_flag+'&copy='+_copy+'&app='+_app,
    				type: 'POST',
    				data: $('#postItem').serialize(),
    				success: function(data) {
    				  	if(data == null) data = '';
    				  	printWindow = window.open('about:blank', 'Print Bill '+_mode, 'height=600,width=800');
    				 	printWindow.document.write(data);
    			 	 	printWindow.document.close();
    				}
    		  	});
    		}
    		else{
    		    $.ajax({
    				url: $('#baseUrl').val() + 'posr/makePrint/&kode='+_meja+'&mode='+_mode+'&flag='+_flag+'&copy='+_copy+'&app='+_app,
    				type: 'POST',
    				data: $('#postItem').serialize(),
    				success: function(data) {
    				    $('#_dataBill').append(data);
    				}
    		  	});
    		}
		}, index * delay);
	  });
	  //hidePrint();
	};
	
	// Reset Bill Untuk Print
	_resetBill = false;
	resetBill = function(){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		if(_resetBill != false){
			_resetBill.abort();
		}
		
		_resetBill = $.ajax({
			url: $('#baseUrl').val()+'posr/resetBill/&kode='+_meja,
			type : 'POST',
			data : $('#postItem').serialize(),
			success: function(data){
				$('#_dataBill').html(data);
				alert('Anda bisa print ulang nota bar/dapur');
			}
		});
	}
	$('._btnReset').click(function(){
		_conf = confirm("Print Ulang Nota?");
		if(_conf){
			resetBill();
		}
	})
	
	// Pindah Meja
	_pindahMeja = false;
	pindahMeja = function(_mejaBaru){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		if(_meja == _mejaBaru){
			alert('Pilih Meja Yang Beda!');
			return;
		}
		if(_pindahMeja != false){
			_pindahMeja.abort();
		}
		$('#_dataBill').html('Loading...');
		_pindahMeja = $.ajax({
			url: $('#baseUrl').val()+'posr/pindahMeja/&kode='+_meja+'&new_meja='+_mejaBaru,
			type : 'POST',
			data : $('#postItem').serialize(),
			success: function(data){
				$('#_dataBill').html(data);
			}
		});
	}
	_loadPilihMeja = false;
	loadPilihMeja = function(){
		if(_loadPilihMeja != false){
			_loadPilihMeja.abort();
		}
		_loadPilihMeja = $.ajax({
			url: $('#baseUrl').val()+'posr/pilihMeja/',
			type : 'POST',
			data : $('form').serialize(),
			success: function(data){
				$('#_pilihMeja').html(data);
				$('#_dialogPindahMeja').dialog('open');
			}
		});
	}
	$('#_dialogPindahMeja').dialog({
		autoOpen: false,
		resizable: false,
		draggable: false,
		width: 300,
		height: 120,
		modal: true,
		closeText: '',
		open: function() {
			$('body').append('<div id="_overlay"></div>');
			//$(this).parent().css('z-index', 9999);
		},
		close: function() {
			$('#_overlay').remove();
		},
		buttons: {
			"OK": function() {
				pilihMeja = $('#_pilihMeja').val();
				pindahMeja(pilihMeja);
				$(this).dialog("close");
			},
			"Cancel": function() {
				$(this).dialog("close");
			}
		}
	});
	$('._btnPindah').click(function(){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		loadPilihMeja();
	})
	
	/* Tab Right */
	// Delete Item
	_makeDeleteItem = false;
	makeDeleteItem = function(_user,_pass,_no_item,_ket=""){
		_meja = $('#kodemeja').val();
		if(_meja === ''){
			alert('Pilih Meja Terlebih Dahulu!');
			return;
		}
		if(_makeDeleteItem != false){
			_makeDeleteItem.abort();
		}
		_nPass = excript(_pass, 0, 0);
		_makeDeleteItem = $.ajax({
			url: $('#baseUrl').val()+'posr/checkSupervisorToDelete/&kode='+_meja, //&user='+_user+'&pass='+_nPass,
			type : 'POST',
			data : {
				user: _user,
				pass: _nPass,
				no_item: _no_item,
				ket: _ket
			},
			success: function(data) {
				$('#_dataBill').html(data);
			}
		});
	}
	$('#_dialogBatal').dialog({
		autoOpen: false,
		resizable: false,
		draggable: false,
		height: 'auto',
		modal: true,
		closeText: '',
		open: function() {
			$('body').append('<div id="_overlay"></div>');
			//$(this).parent().css('z-index', 9999);
		},
		close: function() {
			$('#_overlay').remove();
		},
		buttons: {
			"Cancel": function() {
				$(this).dialog("close");
			},
			"Ok": function() {
				_ket = $('#_ket').val();
				_user = $('#_user').val();
				_pass = $('#_pass').val();
				_no_item = $('#_no_item').val();
				if (_ket && _user && _pass) {
					makeDeleteItem(_user, _pass, _no_item, _ket);
					$(this).dialog("close");
				} else {
					alert("Semua input harus diisi!");
				}
			}
		}
	});
	
	
	/* Misc */
	// Idle Polling
	_idleTimeout = false;
    idleTimeout = function() {
        clearTimeout(_idleTimeout);
        _idleTimeout = setTimeout(idleFunction, 60000);
    }
    idleFunction = function(){
        console.log("User is idle for 10 seconds.");
        _meja = $('#kodemeja').val();
		if(_meja === ''){
			makeLoadMeja("<?php echo $def_meja->kd_merek ?>");
			idleTimeout();
			return;
		}
		if($('#_diskg').val() == '0'){
    		makeLoadMeja(_meja);
        }
    	idleTimeout();
    }
    $(document).on('mousemove keypress click', idleTimeout);
    idleTimeout();
	_refreshTime = false;
	refreshTime = function(){
		if(_refreshTime != false){
			_refreshTime.abort();
		}
		_refreshTime = $.ajax({
			url: $('#baseUrl').val()+'posr/refreshTime/',
			type : 'POST',
			data : $('form').serialize(),
			success: function(data){
				$("#_time").text(data);
			}
		});
	}
    setInterval(refreshTime, 60000);
})
</script>

