@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="index.html"><i class="icon-home2 position-left"></i> Pembelian</a></li>
			<li class="active">Laporan Pembelian</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Laporan Pembelian per Barang</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	{{-- <button class="btn btn-primary" id="btn_tambah_carabayar"><i class=""></i>Tambah</button> --}}
	    	<form class="form-horizontal" autocomplete="off" id="form_laporan">
	    		<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    		<div class="col-sm-12">
	    			<input type="hidden" name="jenis">
		    		<div class="form-group">
		    			<label class="control-label col-sm-2">Barang</label>
		    			<div class="col-sm-8">
		    				<select class="form-control select-search" name="barang">
		    					
		    				</select>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-6">
	    			<input type="hidden" name="jenis">
		    		<div class="form-group">
		    			<label class="control-label col-sm-4">Tanggal Awal</label>
		    			<div class="col-sm-8">
		    				<input class="form-control date_awal" type="text" name="tanggal_awal" required>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-6">
		    		<div class="form-group">
		    			<label class="control-label col-sm-4">Tanggal Akhir</label>
		    			<div class="col-sm-8">
		    				<input class="form-control date_akhir" type="text" name="tanggal_akhir" required>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-12">
		    		<div class="form-group pull-right">
		    			<button type="submit" id="btn_cetak" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Cetak Laporan Pembelian Per Barang"><i class="icon-printer position-left"></i>Cetak</button>
		    			
		    		</div>
	    		</div>
	    	</form>
	    </div>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Laporan Pembelian per Penyedia</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	{{-- <button class="btn btn-primary" id="btn_tambah_carabayar"><i class=""></i>Tambah</button> --}}
	    	<form class="form-horizontal" autocomplete="off" id="form_laporan_penyedia">
	    		<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    		<div class="col-sm-12">
	    			<input type="hidden" name="jenis">
		    		<div class="form-group">
		    			<label class="control-label col-sm-2">Penyedia</label>
		    			<div class="col-sm-8">
		    				<select class="form-control select-search" name="penyedia">
		    					
		    				</select>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-6">
	    			<input type="hidden" name="jenis">
		    		<div class="form-group">
		    			<label class="control-label col-sm-4">Tanggal Awal</label>
		    			<div class="col-sm-8">
		    				<input class="form-control date_awal" type="text" name="tanggal_awal_penyedia" required>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-6">
		    		<div class="form-group">
		    			<label class="control-label col-sm-4">Tanggal Akhir</label>
		    			<div class="col-sm-8">
		    				<input class="form-control date_akhir" type="text" name="tanggal_akhir_penyedia" required>
		    			</div>
		    		</div>
	    		</div>
	    		<div class="col-sm-12">
		    		<div class="form-group pull-right">
		    			<button type="submit" id="btn_cetak_penyedia" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Cetak Laporan Per Penyedia"><i class="icon-printer position-left"></i>Cetak</button>
		    			
		    		</div>
	    		</div>
	    	</form>
	    </div>
	</div>
</div>
<script type="text/javascript">

	$(document).ready(function(){
		get_barang();
		get_penyedia();
	})

	function get_barang(){
		$.ajax({
			url: '{{ url('laporan_pembelian/get_barang') }}',
			success: function(respon){
				$("[name=barang]").html('');
				if(respon.length > 0){
					for(i in respon){
						$("[name=barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].satuan+'">'+respon[i].kategori+' - '+respon[i].nama_sub+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_penyedia(){
		$.ajax({
			url: '{{ url('laporan_pembelian/get_penyedia') }}',
			success: function(respon){
				$("[name=penyedia]").html('');
				if(respon.length > 0){
					for(i in respon){
						$("[name=penyedia]").append('<option value="'+respon[i].id_penyedia+'">'+respon[i].nama+' - '+respon[i].pic+'</option>');
					}
				}
			}
		})
	}

	$("#btn_cetak").click(function(){
		var barang = $("[name=barang]").val();
		var tanggal_awal = $("[name=tanggal_awal]").val();
		var tanggal_akhir = $("[name=tanggal_akhir]").val();
		if(tanggal_awal != '' && tanggal_akhir != ''){
			var url = "{{ url('laporan_pembelian/cetak_kategori_barang') }}";
			$("[name=jenis]").val(1);
			$("#form_laporan").attr('action', url);
			$("#form_laporan").attr('method', 'post');
			$("#form_laporan").attr('target', '_blank');
			$("#form_laporan").submit();
		}

	})

	$("#btn_cetak_penyedia").click(function(){
		var penyedia = $("[name=penyedia]").val();
		var tanggal_awal = $("[name=tanggal_awal_penyedia]").val();
		var tanggal_akhir = $("[name=tanggal_akhir_penyedia]").val();
		if(tanggal_awal != '' && tanggal_akhir != ''){
			var url = "{{ url('laporan_pembelian/cetak_kategori_penyedia') }}";
			$("[name=jenis]").val(1);
			$("#form_laporan_penyedia").attr('action', url);
			$("#form_laporan_penyedia").attr('method', 'post');
			$("#form_laporan_penyedia").attr('target', '_blank');
			$("#form_laporan_penyedia").submit();
		}

	})

</script>


@endsection