<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="function/dataTables/media/css/demo_page.css">
<link rel="stylesheet" href="function/dataTables/media/css/demo_table_jui.css">
<link rel="stylesheet" href="function/dataTables/media/themes/smoothness/jquery-ui-1.8.4.custom.css">
<link rel="stylesheet" href="include/css/style_tabs.css">
<script type="text/javascript" src="function/dataTables/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript">
	$(document).ready(function(){ 
		$("#fromdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#todate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready( function () {
		var oTable = $('#myTables1').dataTable( {
			 "sDom": 'R<"H"lfr>t<"F"ip>',
			 "bJQueryUI": true,
			 "sPaginationType": "full_numbers",
			 "iDisplayLength" :10
		});
	});
	$(document).ready( function () {
		var oTable = $('#myTables2').dataTable( {
			 "sDom": 'R<"H"lfr>t<"F"ip>',
			 "bJQueryUI": true,
			 "sPaginationType": "full_numbers",
			 "iDisplayLength" :10
		});
	});	
	$(document).ready( function () {
		var oTable = $('#myTables3').dataTable( {
			 "sDom": 'R<"H"lfr>t<"F"ip>',
			 "bJQueryUI": true,
			 "sPaginationType": "full_numbers",
			 "iDisplayLength" :10
		});
	});	
	function setTrColor(obj, color)
	{
		obj.style.backgroundColor=color;
		obj.onmouseout = function(){
				obj.style.backgroundColor=''; 
		}
	}
	function search_click(){
		form.action ='?page=Data-EXBC&Act=CARI';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function add_click(){
		form.action ='?page=Proses-EXBC&Act=ADD';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function adds_click(){
		form.action ='?page=Proses-EXBC&Act=ADDS';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function details_click(id){
		form.action ='?page=Proses-EXBC&Act=DETAILS&stock_id='+id;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function deletes_click(id){
		var a = confirm("Apakah anda yakin akan menghapus data?");
		if (a == true){
			form.action ='?page=Proses-EXBC&Act=DELETES&stock_id='+id;
			form.method = 'post';
			form.submit();		
			return true;
		}	
	}
	function posting_click(id,code){
		form.action ='?page=Proses-EXBC&Act=POSTING&obc_id='+id;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function detail_click(id){
		form.action ='?page=Proses-EXBC&Act=DETAIL&obc_id='+id;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function delete_click(id){
		var a = confirm("Apakah anda yakin akan menghapus data?");
		if (a == true){
			form.action ='?page=Proses-EXBC&Act=DELETE&obc_id='+id;
			form.method = 'post';
			form.submit();		
			return true;
		}	
	}
	function excel1_click(id){
		form.action ='./transaksi/manual/excel_exbc.php?obc_id='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function excel2_click(){
		form.action ='./transaksi/manual/excel_stock_exbc.php';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function print_click(id){
		window.open("popup/print_exbc.php?obc_id="+id,"mywindow","menubar=1,scrollbars=1,resizable=1,width=700,height=1000");
	}
</script>
<?php
$cek = isset($_REQUEST['cek']) ? $_REQUEST['cek'] : 1;
if(isset($_REQUEST['Act'])=="CARI"){
	 $fromdate	 = isset($_REQUEST['fromdate']) ? $_REQUEST['fromdate'] : $start_date;
	 $todate     = isset($_REQUEST['todate']) ? $_REQUEST['todate'] : $end_date; 
	 if($cek==1){
		$check1 ="checked=checked";
		$check2 ="";
		$check3 ="";
	}elseif($cek==2){
		$check1 ="";
		$check2 ="checked=checked";
		$check3 ="";
	}elseif($cek==3){
		$check1 ="";
		$check2 ="";
		$check3 ="checked=checked";
	}	
 }else{
	 $fromdate	 = $start_dateexbc;
	 $todate     = $end_dateexbc;	
	 $check1 ="checked=checked";
	 $check2 ="";
	 $check3 ="";
 }
 $month 	= substr($fromdate,5,2);
 $year		= substr($fromdate,0,4);
?>
</head>
<body>
<form action="#" method="post" name="form">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
	<td colspan="11" align="center"><h1><b>DATA TRANSAKSI & STOCK EXBC</b></h1></td>
  </tr>
  <tr>
	<td colspan="11">Periode :
	     <!--<select id="bulan" name="bulan">
		   <?php
			$bln = array('','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
			for($n=1; $n<=12; $n++){
			if ($n == $bulan) {
				$cek = " selected";
			} else { $cek=""; }
		   ?>
		   	<option value="<?=$n;?>" <?=$cek;?>><?=$bln[$n];?></option>
		   <?php } ?>
		  </select>
		  <input type="text" id="tahun" name="tahun" size="4" value="<?=$tahun;?>">-->
		  <input type="text" id="fromdate" name="fromdate" size="9" value="<?=$fromdate;?>" style="border-collapse:inherit"  readonly="true">&nbsp;s/d&nbsp;
	      <input type="text" id="todate" name="todate" size="9" value="<?=$todate;?>" style="border-collapse:inheri" readonly="true">
	      <input type="button" name="cari" value="CARI" style="cursor:pointer" onclick="search_click();">
		  <!--<input type="button" name="export" value="Export to Excel" style="cursor:pointer" onClick="excel_click();" />
		  <input type="button" name="pdf" value="Export to PDF" style="cursor:pointer" onClick="pdf_click();"/>-->
	</td>		
  </tr>
</table>  
<input type="radio" name="tab" id="tab1" <?=$check1;?>><label id="label1" for="tab1">Data Transaksi</label>
<input type="radio" name="tab" id="tab2" <?=$check2;?>><label id="label2" for="tab2">Stock Exbc</label>
<input type="radio" name="tab" id="tab3" <?=$check2;?>><label id="label3" for="tab3">Data Stock</label>
<div class="content1">
	<img src="images/btn_add.png" height="30" width="30" title="Tambah Manual" border="0" style="cursor:pointer" onclick="add_click();" />
    <table id="myTables1" class="display" cellpadding="0" cellspacing="0">
        <thead>	
      <tr>
        <th>No</th>
        <th>Tanggal</th>
        <th>Kode Barang</th>
        <th>Nama Barang</th>
        <th>Satuan</th>
        <th>Jumlah</th>	
        <th>Action</th>
      </tr>
      </thead>
        <tbody>
      <?php
        $no=1; $gtprice=0;
        $qd = mysql_query("SELECT a.*, b.prod_code, b.prod_name, b.prod_sat FROM outexbc a INNER JOIN product b ON b.id=a.obc_prodid
		                   WHERE a.obc_status<>100 AND a.obc_date BETWEEN '$fromdate' AND '$todate' ORDER BY id DESC");
        while($dd=mysql_fetch_array($qd)){	
        ?> 
         <tr onmouseover="setTrColor(this, '#FF9900');">
            <td align="center"><?=$no;?>.</td>
            <td align="center"><?=$dd['obc_date'];?></td>            
            <td align="left"><?=$dd['prod_code'];?></td>
            <td align="left"><?=$dd['prod_name'];?></td>
            <td align="center"><?=$dd['prod_sat'];?></td>
            <td align="right"><?=number_format($dd['obc_qty'],5,'.',',');?></td>
			<td align="center">
				<img src="images/btn_print.png" height="20" width="20" title="Print" border="0" style="cursor:pointer" onclick="print_click('<?=$dd['id'];?>');" />
				<img src="images/btn_import.png" height="20" width="20" title="Excel" border="0" style="cursor:pointer" onclick="excel1_click('<?=$dd['id'];?>');" />
				<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onclick="delete_click('<?=$dd['id'];?>');" />
			</td>
          </tr>	  
      <?php $no++; }  ?> 
      </tbody> 
    </table>
</div>
<div class="content2">
	Download to Excel : 
		<img src="images/btn_import.png" height="30" width="30" title="Excel" border="0" style="cursor:pointer" onclick="excel2_click();" />
	<table id="myTables2" class="display" cellpadding="0" cellspacing="0">
        <thead>	
      <tr>
        <th>No</th>
        <th>Jenis</th>
        <th>No. Daftar</th>
        <th>Tgl Daftar</th>
        <th>Kode Barang</th>
        <th>Nama Barang</th>
        <th>Satuan</th>
        <th>S.Awal</th>	
		<th>Masuk</th>	
        <th>Keluar</th>
        <th>S.Akhir</th>
		<th>Valuta</th>
		<th>Harga</th>
      </tr>
      </thead>
        <tbody>
      <?php
        $no=1; 
        $qd = mysql_query("SELECT b.prodid, b.doctype, b.docno, b.docdate, b.begqty, b.inqty, b.outqty, ((b.begqty+b.inqty)-b.outqty) endqty, b.price, b.prod_code, 
					b.prod_name, b.prod_sat, b.curr FROM
					(SELECT a.prodid, a.doctype, a.docno, a.docdate, SUM(a.begqty) begqty, SUM(a.inqty) inqty, SUM(a.outqty) outqty, a.price, b.prod_code, b.prod_name, b.prod_sat, a.curr  FROM
					(SELECT stock_prodid prodid, stock_doctype doctype, stock_docno docno, stock_docdate docdate, stock_qty begqty, 0 inqty, 0 outqty, stock_price price, stock_currency curr 
					FROM stock_exbc WHERE stock_status=10 AND MONTH(stock_date)='$month' AND YEAR(stock_date)='$year'
					UNION ALL
					SELECT b.incd_prodid prodid, a.inch_doctype doctype , a.inch_docno docno, a.inch_docdate docdate, 0 begqty, b.incd_qty inqty, 0 outqty, CASE WHEN a.valuta='IDR' THEN (b.incd_price/b.incd_qty) ELSE (b.incd_price_usd/b.incd_qty) END AS price, a.valuta curr 
					FROM incoming a
					INNER JOIN incoming_detail b ON b.incd_hid=a.id
					WHERE a.inch_status=20 AND a.inch_docdate BETWEEN '$fromdate' AND '$todate'
					UNION ALL
					SELECT a.obcd_prodid prodid, a.obcd_doctype doctype , a.obcd_docno docno, a.obcd_docdate docdate, 0 begqty, 0 inqty, a.obcd_qty outqty, 0 price, '' curr 
					FROM outexbc_detail a
					INNER JOIN outexbc b ON b.id=a.obcd_hid
					WHERE b.obc_status=20 AND b.obc_date BETWEEN '$fromdate' AND '$todate'
					) a
					INNER JOIN product b ON b.id=a.prodid
					WHERE b.prod_cat IN(1,5,6) GROUP BY a.prodid, a.doctype, a.docno, a.docdate) b
					ORDER BY b.docno, b.docdate, b.prod_code ASC");
        while($dd=mysql_fetch_array($qd)){	
        ?> 
         <tr onmouseover="setTrColor(this, '#FF9900');">
            <td align="center"><?=$no;?>.</td>
            <td align="center"><?=$dd['doctype'];?></td>
            <td align="center"><?=$dd['docno'];?></td>
            <td align="center"><?=$dd['docdate'];?></td>
            <td align="left"><?=$dd['prod_code'];?></td>
            <td align="left"><?=$dd['prod_name'];?></td>
            <td align="center"><?=$dd['prod_sat'];?></td>
            <td align="right"><?=number_format($dd['begqty'],2,'.',',');?></td>
			<td align="right"><?=number_format($dd['inqty'],2,'.',',');?></td>
            <td align="right"><?=number_format($dd['outqty'],2,'.',',');?></td>
            <td align="right"><?=number_format($dd['endqty'],2,'.',',');?></td>
			<td align="center"><?=$dd['curr'];?></td>
			<td align="right"><?=number_format($dd['price'],2,'.',',');?></td>
          </tr>	  
      <?php $no++; }  ?> 
      </tbody> 
    </table>
</div>
<div class="content3">
		Tambah : <img src="images/btn_add.png" height="30" width="30" title="Tambah Stok" border="0" style="cursor:pointer" onclick="adds_click();" />
	<table id="myTables3" class="display" cellpadding="0" cellspacing="0">
        <thead>	
      <tr>
        <th>No</th>
        <th>Jenis</th>
        <th>No. Daftar</th>
        <th>Tgl Daftar</th>
        <th>Kode Barang</th>
        <th>Nama Barang</th>
        <th>Satuan</th>
        <th>Jumlah</th>	
		<th>No Aju</th>	
        <th>No Urut</th>
        <th>Action</th>
      </tr>
      </thead>
        <tbody>
      <?php
        $no=1; 
        $qd = mysql_query("SELECT a.*, b.prod_code, b.prod_name, b.prod_sat 
		FROM stock_exbc a INNER JOIN product b ON b.id=a.stock_prodid 
		WHERE a.stock_status=10 AND MONTH(a.stock_date)='$month' AND YEAR(a.stock_date)='$year' ORDER BY a.stock_docdate, b.prod_code ASC");
        while($dd=mysql_fetch_array($qd)){	
        ?> 
         <tr onmouseover="setTrColor(this, '#FF9900');">
            <td align="center"><?=$no;?>.</td>
            <td align="center"><?=$dd['stock_doctype'];?></td>
            <td align="center"><?=$dd['stock_docno'];?></td>
            <td align="center"><?=$dd['stock_docdate'];?></td>
            <td align="left"><?=$dd['prod_code'];?></td>
            <td align="left"><?=$dd['prod_name'];?></td>
            <td align="center"><?=$dd['prod_sat'];?></td>
            <td align="right"><?=number_format($dd['stock_qty'],2,'.',',');?></td>
			<td align="center"><?=$dd['stock_noaju'];?></td>
			<td align="center"><?=$dd['stock_nourut'];?></td>
			<td align="center">
			<img src="images/btn_edit.png" width="20" height="20"  border="0"  title="Edit" style="cursor:pointer" onclick="details_click('<?=$dd['id'];?>');"  />
			<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onclick="deletes_click('<?=$dd['id'];?>','<?=$dd['prod_code'];?>');"  />
			</td>
          </tr>	  
      <?php $no++; }  ?> 
      </tbody> 
    </table>
</div>
</form>
</body>
</html>
