@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> Produksi</a></li>
			<li class="active">Laporan Hasil</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Laporan Hasil</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<!-- <a href="{{url('barangmasuk/tambah')}}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a> -->
	    	<button class="btn btn-info" type="button" id="btn_cari" style="margin-bottom: 1%;">Cari</button>
	    </div>

	    <table class="table dataTable table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Nomor</th>
					<th>Tanggal Terima</th>
					<th>Nomor Order</th>
					<th>Nomor Bon</th>
					<th>Tanggal Bon</th>
					<th>Pemroses</th>
					<th>Proses Produksi</th>
                    <th>Status</th>
					<th class="text-center"></th>
				</tr>
			</thead>
			<tbody>
				 

					
			</tbody>
	    </table>
	</div>
</div>

<div class="modal fade" id="exampleModal2" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog" role="document">
	    <div class="modal-content">
	    	<div class="modal-header">
	    		<h5 class="modal-title" id="exampleModalLabel">Cari</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      	<div class="modal-body">
	      		<input type="hidden" name="jenis" value="0">
	      		<form class="form-horizontal" autocomplete="off">
	      			
	      			<div class="form-group">
	      				<div class="control-label col-sm-4">Tanggal Bon</div>
	      				<div class="col-sm-4">
		    				<input type="text" name="tgl_awal" class="form-control date_awal" value="{{ date('d-m-Y') }}" required readonly>
		    			</div>
		    			<div class="col-sm-4">
		    				<input type="text" name="tgl_akhir" class="form-control date_akhir" value="{{ date('d-m-Y') }}" required readonly>
		    			</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      					<select class="select-search" name="popup_proses" id="popup_proses">
	      						{{-- <option value="0">Semua Proses</option> --}}
	      						@php
	      						foreach($data['proses']->get() as $p){
	      						@endphp
	      						<option value="{{ $p->id_proses }}">{{ $p->nama_proses }}</option>
	      						@php
	      						}
	      						@endphp
	      					</select>	      					
	      				</div>
	      			</div>

	      			<div class="form-group">
	      				<div class="col-sm-12">
	      					<button type="button" class="btn btn-primary" id="popup_btn_cari">Cari</button>
	      				</div>
	      			</div>
	      		</form>

	      		<form class="form-horizontal" autocomplete="off">	
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      					<select class="select-search" name="popup_proses_semua" id="popup_proses_semua">
	      						<option value="0">Semua Proses</option>
	      						@php
	      						foreach($data['proses']->get() as $p){
	      						@endphp
	      						<option value="{{ $p->id_proses }}">{{ $p->nama_proses }}</option>
	      						@php
	      						}
	      						@endphp
	      					</select>	      					
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Tampilkan Semua</label>
	      				<div class="col-sm-8">
	      					<select class="select-search" name="popup_semua" id="popup_semua">
	      						{{-- <option value="0">Tidak</option> --}}
	      						<option value="1">Ya</option>
	      					</select>
	      					<p class="help-block">Memilih ya akan menampilkan semua data</p>			
	      				</div>
	      			</div>
	      			
	      			<div class="form-group">
	      				<div class="col-sm-12">
	      					<button type="button" class="btn btn-primary" id="popup_btn_cari_2">Cari</button>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	      	</div>
	    </div>
	</div>
</div>

<script type="text/javascript">

	var table;
	$(document).ready(function(){
		table = $(".dataTable").DataTable({
			processing: true,
	        serverSide: true,
	        searchDelay: 2000,
	        ajax: {
	        	url : '{{ url('barangmasuk/get_data') }}',
	        	type : "post",
	        	headers : {
	        		'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		      	},
	        	data : function(data){
	        		data['jenis'] = $("[name=jenis]").val();
	        		data['proses'] = $("[name=popup_proses]").val();
	        		data['proses_semua'] = $("[name=popup_proses_semua]").val();
	        		data['tgl_awal'] = $("[name=tgl_awal]").val();
	        		data['tgl_akhir'] = $("[name=tgl_akhir]").val();
	        		data['is_semua'] = $("[name=popup_semua]").val();
	        	}
	        },
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}, className: 'text-center'},
			  	{data: 'nomor', name: 'nomor'},
			  	{data: 'tanggal_laporan', name: 'tanggal_laporan'},
	            {data: 'no_workorder', name: 'no_workorder'},
	            {data: 'nomor_bon', name: 'nomor_bon'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'posisi', name: 'posisi'},
	            {data: 'proses', name: 'proses'},
	            {data: 'status', name: 'status'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false},
	        ],
	        "order": [[ 8, "desc" ]]
		});
		

	})

	$("#btn_cari").click(function(){
		$("#exampleModal2").modal("show");
	})

	$("#popup_btn_cari").click(function(){
		$("[name=jenis]").val('0');
		$("#exampleModal2").modal("hide");
		table.ajax.reload();
	})

	$("#popup_btn_cari_2").click(function(){
		$("[name=jenis]").val('1');
		$("#exampleModal2").modal("hide");
		table.ajax.reload();
	})

	$("#popup_proses").change(function(){

	})

	function hapus(this_){
		var id = $(this_).attr('id_hasil');
		var jenis = $(this_).attr('jenis');
		swal({
			title: 'Anda yakin akan menghapus item ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('barangmasuk/hapus_hasil')}} ",
					type: 'post',
					data: {id : id, jenis : jenis},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						table.ajax.reload();

						if(respon.status == '0'){
							yakin(id, 1);
						}else{
							table.ajax.reload();
						}
					}
				})
		 	}
		})
	}

	function yakin(id, status){
		var id = id;
		var jenis = '1';
		swal({
			title: 'Dengan menhapus item ini, akan mengakibatkan berubahan data yang ada di persediaan. Anda yakin?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('barangmasuk/hapus_hasil')}} ",
					type: 'post',
					data: {id : id, jenis : jenis},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						table.ajax.reload();
					}
				})
		 	}
		})
	}

	

</script>
@endsection