<meta name="viewport" content="width=device-width, initial-scale=1">
<?php
include 'connect.php';
define('YBASE',true);
session_start();


if (isset($_SESSION['yuser'])) {
			include_once 'config/log.php';
	$mtime = microtime(); $mtime = explode (" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime;
} else {
	header('location:login.php');	
}	

$jabat=$_SESSION['jabat'];


	if ($jabat=='1') {
    $query = mysqli_query($con,"SELECT kdslm,nmslm,kdgudang,curdate() as tgl from salesman where kdslm='$_SESSION[yuser]';");
	} else {
		$query = mysqli_query($con,"SELECT kdslm,nmslm,kdgudang,curdate() as tgl from salesman where kdslm='$_GET[id]';");
	}
	    $data  = mysqli_fetch_array($query);
	
	$system="Select cabang,kdgudang from system limit 1";
	$dsystem=mysqli_query($con,$system);  
	$datasystem= mysqli_fetch_array($dsystem);
	$_cbg=$datasystem['cabang'];
	$_sgd=$datasystem['kdgudang'];
	$_gdg=$data['kdgudang'];
	$_tgl=$data['tgl'];
	
if ($data === false) {
    echo "Data tidak ditemukan!
<a href='listmuatsales.php'>Kembali</a>";
    exit();
}
?>
<html>
 <head>
  <title>IBS</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/layout.css">
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
    <link rel="stylesheet" type="text/css" href="css/easyui.css">
    <link rel="stylesheet" type="text/css" href="css/icon.css">
	<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.css">
    <link rel="stylesheet" type="text/css" href="css/jquery_notification.css">
    <link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css"/>
    <link rel="stylesheet" type="text/css" href="css/jpaging.css">
    <link rel="stylesheet" type="text/css" href="css/ui.datepicker.css"/>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
	<link rel="stylesheet" type="text/css" href="css/jquery-ui.css"/>   
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.20.custom.min.js"></script>
    <script type='text/javascript' src='js/jquery.paginate.js'></script>
    <script type="text/javascript" src="js/ui.core.js"></script>
    <script type='text/javascript' src="js/jquery.autocomplete.js"></script>
    <script type="text/javascript" src="js/ui.datepicker.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/clock.js"></script>
    <script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
	<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
    <script language="JavaScript">
    var ajaxRequest;
    function getAjax() { //fungsi untuk mengecek AJAX pada browser
        try {
            ajaxRequest = new XMLHttpRequest();
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
    }
    function autoComplete() { //fungsi menangkap input search dan menampilkan hasil search
        getAjax();
        input = document.getElementById('kdbrg').value;if (input == "") {
            document.getElementById("hasil").innerHTML = "";
        }
        else {
            ajaxRequest.open("GET","cariretur.php?input="+input);
            ajaxRequest.onreadystatechange = function() {
                document.getElementById("hasil").innerHTML = ajaxRequest.responseText;
            }
            ajaxRequest.send(null);
        }
    }
    function autoInsert(kdbrg,namabrg1,isi3,hrgbeli,gabung,saldo) { //fungsi mengisi input text dengan hasil pencarian yang dipilih
        document.getElementById("kdbrg").value = kdbrg;
        document.getElementById("namabrg1").value = gabung;
		document.getElementById("saldo").value = saldo;
		document.getElementById("hasil").innerHTML = "";
    }
 </script>
	<script type="text/javascript">    
	
    //fungsi displayTime yang dipanggil di bodyOnLoad dieksekusi tiap 1000ms = 1detik
    function tampilkanwaktu(){
        //buat object date berdasarkan waktu saat ini
        var waktu = new Date();
        //ambil nilai jam, 
        //tambahan script + "" supaya variable sh bertipe string sehingga bisa dihitung panjangnya : sh.length
        var sh = waktu.getHours() + ""; 
        //ambil nilai menit
        var sm = waktu.getMinutes() + "";
        //ambil nilai detik
        var ss = waktu.getSeconds() + "";
        //tampilkan jam:menit:detik dengan menambahkan angka 0 jika angkanya cuma satu digit (0-9)
        document.getElementById("clock").innerHTML = (sh.length==1?"0"+sh:sh) + "." + (sm.length==1?"0"+sm:sm) + "." + (ss.length==1?"0"+ss:ss);
    }
</script>
 <SCRIPT language=Javascript>
<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))

return false;
return true;
}
function Desimal(obj){
    a=obj.value; 
    var reg=new RegExp(/[0-9]+(?:\.[0-9]{0,2})?/g)
    b=a.match(reg,''emoticon-Wink;
    if(b==null){
        obj.value='';
    }else{
        obj.value=b[0];
    }
   
}
//-->
</SCRIPT>

	<style type="text/css">
.classname {
	-moz-box-shadow:inset 0px 1px 0px 0px #cae3fc;
	-webkit-box-shadow:inset 0px 1px 0px 0px #cae3fc;
	box-shadow:inset 0px 1px 0px 0px #cae3fc;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #FF0000), color-stop(1, #4197ee) );
	background:-moz-linear-gradient( center top, #FF0000 5%, #4197ee 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#4197ee');
	background-color:#FF0000;
	-webkit-border-top-left-radius:20px;
	-moz-border-radius-topleft:20px;
	border-top-left-radius:20px;
	-webkit-border-top-right-radius:20px;
	-moz-border-radius-topright:20px;
	border-top-right-radius:20px;
	-webkit-border-bottom-right-radius:20px;
	-moz-border-radius-bottomright:20px;
	border-bottom-right-radius:20px;
	-webkit-border-bottom-left-radius:20px;
	-moz-border-radius-bottomleft:20px;
	border-bottom-left-radius:20px;
	text-indent:0;
	border:1px solid #469df5;
	display:inline-block;
	color:#ffffff;
	font-family:Verdana;
	font-size:10px;
	#font-weight:bold;
	font-style:normal;
	height:15px;
	line-height:15px;
	width:30px;
	text-decoration:none;
	text-align:top-center;
	text-shadow:1px 1px 0px #287ace;
}
.classname:hover {
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #4197ee), color-stop(1, #79bbff) );
	background:-moz-linear-gradient( center top, #4197ee 5%, #79bbff 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#4197ee', endColorstr='#79bbff');
	background-color:#4197ee;
}.classname:active {
	position:relative;
	top:1px;
}

    tbody > tr:nth-child(2n+1) > td, tbody > tr:nth-child(2n+1) > th {
        background-color: #ededed;
    }
    table{
        width: 95%;
        margin: auto;
        border-collapse: collapse;
        box-shadow: darkgrey 3px;
    }
    thead tr {
        background-color: #36c2ff;
    }
	
</style>
<style type="text/css">
.timbul {
	-moz-box-shadow:inset 0px 1px 0px 0px #fce2c1;
	-webkit-box-shadow:inset 0px 1px 0px 0px #fce2c1;
	box-shadow:inset 0px 1px 0px 0px #fce2c1;
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #3a0cf0), color-stop(1, #176157) );
	background:-moz-linear-gradient( center top, #3a0cf0 5%, #176157 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#3a0cf0', endColorstr='#176157');
	background-color:#3a0cf0;
	-webkit-border-top-left-radius:10px;
	-moz-border-radius-topleft:10px;
	border-top-left-radius:10px;
	-webkit-border-top-right-radius:10px;
	-moz-border-radius-topright:10px;
	border-top-right-radius:10px;
	-webkit-border-bottom-right-radius:10px;
	-moz-border-radius-bottomright:10px;
	border-bottom-right-radius:10px;
	-webkit-border-bottom-left-radius:10px;
	-moz-border-radius-bottomleft:10px;
	border-bottom-left-radius:10px;
	text-indent:0px;
	border:2px solid #ed5197;
	display:inline-block;
	color:#dcdeed;
	font-family:Arial Black;
	font-size:12px;
	font-weight:bold;
	font-style:normal;
	height:25px;
	line-height:25px;
	width:100px;
	text-decoration:none;
	text-align:center;
	text-shadow:0px 1px 0px #cc9f52;
}
.timbul:hover {
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #176157), color-stop(1, #3a0cf0) );
	background:-moz-linear-gradient( center top, #176157 5%, #3a0cf0 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#176157', endColorstr='#3a0cf0');
	background-color:#176157;
}.timbul:active {
	position:relative;
	top:1px;
}</style>
<?php

if (isset($_GET['id']))

{
$nobuk=$_GET['id'];
}
else {

	
	$kode=mysqli_query($con,"select concat('PM',date_format(curdate(),'%y%m')) as kode;");
	$kode1= mysqli_fetch_array($kode);
	
	$_kode=$kode1['kode'];
	
		
	$nomourut= mysqli_query($con,"Select func_getid('$_kode','$_cbg') AS nobukti;");
	$nobukti=mysqli_fetch_array($nomourut);
	$nosimpan=$nobukti['nobukti'];
	$nobuk=$nosimpan;
	// $simpan=mysqli_query($con,"insert into somobileheader(cabang,nobukti,custno,tgl,kdslm,stat,kdharga,kdwil,ppn,kdsupplier) 
	//								   values ('$_cbg','$nosimpan','$data[custno]','$data[tgl1]','$_SESSION[yuser]','0','$data[kdharga]','$data[kdwil]',10,'99';");
	
	
}
// cabang  nobukti  tgl     darigd  kegd    stat    kdslm   noreff  
if ($jabat=='1') {
$simpan=mysqli_query($con,"insert ignore into stokkanvasheader(cabang,nobukti,tgl,darigd,kegd,stat,kdslm,jns)
					 value ('$_cbg','$nobuk','$data[tgl]','$data[kdgudang]','$_sgd','0','$_SESSION[yuser]','2');");
					 }
else {
	$simpan=mysqli_query($con,"insert ignore into stokkanvasheader(cabang,nobukti,tgl,darigd,kegd,stat,kdslm,jns)
					 value 's_cbg',$nobuk,$data[kdgudang]',$_sgd','0',$slm','2';");
}
// $simpanok=mysqli_fetch_array($simpan);
//echo $_cbg.$nobuk.$data['custno'].$data['tgl1'].$_SESSION['yuser'].'0'.$data['kdharga'].$data['kdwil'].'10'.'99';
	
?>
<?php
	if ($jabat=='1') {$kdslm=$_SESSION['yuser'];}
	else {$kdslm=$slm;}
	$_SESSION['nobukti'] = $nobuk;	
	$_SESSION['cbg'] = $_cbg;	
	$_SESSION['dgudang'] = $_sgd;	
	$_SESSION['kgudang'] = $_gdg;	
	$_SESSION['kdslm'] = $kdslm;
	
	
?>	
</head>
<body>
<?php
	$total=mysqli_query($con,"select nobukti,stat from stokkanvasheader where nobukti='$nobuk';");
	$tnetto= mysqli_fetch_array($total);
	$_SESSION['stat'] = $tnetto['stat'];		
	$stat=$tnetto['stat'];		
?>
<div style="margin: auto;">
	<div>
			
		<div  style="float:right;margin-right:10px;">
				<td align='center'  type='submit' style='width:70px'><a class='timbul' href="prosesretur.php?id=<?php echo $nobuk; ?>">SIMPAN</a></td>
				
	</div>  
    <table border='1'>
		<thead>
		<p><tr><td>No.Bukti</td><td>: </td><td><?php echo $nobuk; ?></td></tr></p>
		<p><tr><td>Tanggal</td><td>: </td><td><?php echo $_tgl?> </td></tr></p>
        <p><tr><td>Salesman</td><td>: </td><td><?php echo $data['nmslm']; ?></td></tr></p>
        <p><tr><td>Dari Gudang</td><td>: </td><td><?php echo $_gdg; ?></td></tr></p>
        <p><tr><td>Ke Gudang</td><td>: </td><td><?php echo $_sgd; ?></td></tr></p>
		</thead>
       
	</table>	

	
</div> 
<?php if ($stat=='0') {	?>					
<table border='1'>
				
		<form action='simpankanvasretur.php' method='GET' return>
				<table>
					<div style="float:right;">
						<tr>
						<td>
							<input type='text' autocomplete='off' name='kdbrg' onkeyup='autoComplete();' id='kdbrg' style='float:left;width:350px' placeholder='Ketikan Nama Barang ...'  /> <div id='hasil'></div>
						</td>
						</tr>
						</table>
						<table>
						<td>
							<input type='number' style='width:70px' min='0' step='1' autocomplete='off' name='qtyb' id='qtyb' style='width:75px' pattern="[0-9]" placeholder='CRT...'/>				
						</td>
						<td>
							<input type='number' style='width:70px' min='0' step='1' autocomplete='off' name='qtym' id='qtym' style='width:75px' pattern="[0-9]" placeholder='Pack...'/>				
						</td>
						<td>
							<input type='number' style='width:60px' min='0' step='1' autocomplete='off' name='qtyk' id='qtyk' style='width:75px' pattern="[0-9]" placeholder='Pcs...'/>				
						</td>
						<td>																							
							<button type='submit' style='width:70px' ><i class='fa fa-paper-plane'></i>TAMBAH</a></button>
						</td>
						</table>
					</div>									
				</table>	
							
				<table >					
					<td>
						<input type='text' name='namabrg1' id='namabrg1' style='width:250px' placeholder='Nama Barang ...' readonly/>
						<td><input type='text' name='saldo' id='saldo' style='width:100px' placeholder='saldo ...' readonly/></td>
					</td>									
				</table>	
		</form>	
				
</table>
<?php }?>			
<table border="1" style='margin-top:1px;'>

    <thead>
		
        <tr>
            <th>No.</th>
            <th>Keterangan</th>
			<th>Qty</th>
			<th>Aksi</th>
        </tr>
    </thead>
     
    <tbody>
	
<?php

$tampil = "SELECT a.nourut,a.cabang,a.nobukti,a.kdbrg,a.qty,b.namabrg1 from stokkanvasdetail a , barang b 
where a.kdbrg=b.kdbrg and a.nobukti = '$nobuk' order by a.nourut;";


$sql0 = mysqli_query($con,$tampil);  
$satu=mysqli_num_rows($sql0);

if ($satu>0) {

$no = 1; // Untuk penomoran tabel, di awal set dengan 1
while($data = mysqli_fetch_array($sql0)){
	$custno=$data['nobukti'];
	$kdbrg= $data['kdbrg'];
	$_SESSION['kdbrghapus'] = $kdbrg;		
	// $nilait=$nilait+$data['jumlah'];
	
				echo "<tr>";
				echo "<td>".$no++."</td>";
				echo "<td>".$data['namabrg1']."</td>";
				echo "<td align ='right'>".number_format($data['qty'])."</td>";
				if ($stat=='0') {
				echo "<td align='center'>
                <a href='hapusretur.php?id=$data[nourut]' class='classname'>Del</a></td>";
				} else {
				echo "<td align='center'>Del </td>";
                				}
				echo "</tr>";
	
	}	
				$no++; // Tambah 1 setiap kali looping
			}

	?>

</body>
</table>
<?php if ($stat=='0') {?>
<div align='center' style="width:95%; margin: auto;" >
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="autoloadretur.php?id=<?php echo $nobuk; ?>">Autoload</a></td>
<td align='center'  type='submit' style='width:70px'><a class='timbul' href="updateokkanvasmuat.php?id=<?php echo $nobuk; ?>">Proses</a></td>


</div>
<?php }?>
 
 </html>