@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">Form Input 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">
	    	<form class="form-horizontal" method="post" action="" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_barangmasuk" value="{{ $data['masuk']->id_barangmasuk }}">
	    	<input type="hidden" name="id_barangkeluar" value="{{ $data['masuk']->id_barangkeluar }}">
	    	<input type="hidden" name="barangkeluar" value="{{ $data['masuk']->id_barangkeluar }}">
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Selesai</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" placeholder="Tanggal" value="{{ tgl_full($data['masuk']->tanggal_selesai, '') }}" readonly />
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Pengambilan</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="tanggal_pengambilan" placeholder="" value="{{ date('d-m-Y', strtotime($data['masuk']->tanggal_ambil)) }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Perkiraan Selesai</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="tanggal_perkiraan" placeholder="" value="{{ date('d-m-Y', strtotime($data['masuk']->tanggal_perkiraan)) }}" readonly/>
        			</div>
        		</div>

        		<div class="form-group">
        			<label class="control-label col-sm-4">No. SPK</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="no_workorder" placeholder="" value="{{ $data['masuk']->no_workorder }}" readonly/>
        			</div>
        		</div>


        	</div>
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Rekanan</label>
        			<div class="col-sm-8">
        				@php
        				if($data['masuk']->id_rekanan == '0'){
        				$rekanan = '-';
        			}else{
        				$rekanan = $data['masuk']->nama_rekanan.' - '.$data['masuk']->nama_kelompok;
        		}
        				@endphp
        				<input class="form-control" type="text" name="rekanan" placeholder="" value="{{ $rekanan }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Mesin</label>
        			<div class="col-sm-8">
        				@php 
        				if($data['masuk']->id_mesin =='0'){
        				$mesin = '0';
        				}else{
        				$mesin = $data['masuk']->nama_mesin;
        				}@endphp
        				<input class="form-control" type="text" name="mesin" placeholder="" value="{{ $data['masuk']->nama_mesin }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Proses Produksi</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="proses" placeholder="" value="{{ $data['masuk']->nama_proses }}" readonly/>
        			</div>
        		</div>

        		<div class="form-group">
        			<label class="control-label col-sm-4">No. Order</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="no_workorder_barang" placeholder="" value="{{ $data['masuk']->no_workorder_barang }}" readonly/>
        			</div>
        		</div>

       <!------------------ Proses Get Gudang dan Kualitas ---------------------------------> 

        		{{-- <select name="proses_gudang" class="hidden">
        			|<option value="">-- Pilih Gudang --</option>
	      						@php foreach($data['gudang'] as $row){
	      						
	      						@endphp
	      						<option value="{{$row->id_gudang}}" id="{{$row->id_gudang}}" nama="{{$row->nama_gudang}}">{{$row->nama_gudang}}</option>
	      						@php } @endphp
        		</select>
        		<select name="proses_kualitas" class="hidden">
        			|<option value="">-- Pilih Kualitas --</option>
	      						@php foreach($data['kualitas'] as $row){
	      						
	      						@endphp
	      						<option value="{{$row->id_kualitas}}" nama="{{$row->nama_kualitas}}">{{$row->nama_kualitas}}</option>
	      						@php } @endphp
        		</select> --}}

        	</div>
        	
        	<div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Barang Diambil</h5>
	        	<div class="col-ms-12 table-responsive">
		        	<table class="table table-stripped" id="table_barang">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Gudang</th>
								<th>Jumlah</th>
								<th>Kualitas Produksi</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Kualitas Periksa</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
							</tr>
						</thead>
						<tbody>
							@php $no=1; @endphp
							@foreach($data['barang'] as $d) 
							<tr>
								<td>{{$no++}}</td>
								<td>{{ $d->kode_barang }}</td>
								<td>{{ $d->nama_barang }}</td>
								<td>{{ $d->nama_komposisi }}</td>
								<td>{{ $d->nama_gudang }}</td>
								<td>{{ $d->jumlah }}</td>
								<td>{{ $d->nama_kualitas_proses }}</td>
								<td>{{ $d->nama_corak }}</td>
								<td>{{ $d->nama_motif }}</td>
								<td>{{ $d->nama_kualitas }}</td>
								<td>{{ $d->kualitas_dudul }}</td>
								<td>{{ $d->nama_kualitas_periksa }}</td>
								<td>{{ $d->nama_label }}</td>
								<td>{{ $d->nama_cap }}</td>
								<td>{{ $d->nama_kemasan }}</td>
								<td>{{ $d->nama_kemasansatuan }}</td>
								<td>{{ $d->nama_kemasansepuluh }}</td>
								<td>{{ $d->nama_kemasanseratus }}</td>
							</tr>
							@endforeach
						</tbody>
				    </table>
	        	</div>
        	</div>
            
            <div class="col-sm-12 form-group table-responsive">
	        	<h5 class="panel-title">Barang Disetor</h5>
		        	<table class="table table-stripped" id="table_hasil">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Kualitas Proses</th>
								<th>Gudang</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Kualitas Periksa</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
								<th>Shift</th>
							</tr>
						</thead>
						<tbody id="body_setor">
						</tbody>
			    	</table>
        	</div>
        	<div class="col-sm-12">
        	<a href="{{url('barangmasuk')}}" class="btn bg-warning-400">Kembali</a>
            <div class="form-group pull-right">
             	
            </div>
            </div>
	    </div>


		<input type="hidden" name="td_total" class="form-control">
		<input type="hidden" name="td_netto" class="form-control">
	    </form>
	</div>
</div>

<input type="hidden" name="store_konversi">
<input type="hidden" name="store_idproses" placeholder="" value="{{ $data['masuk']->id_proses }}"/>
<input type="hidden" name="store_namaproses" placeholder="" value="{{ strtolower($data['masuk']->nama_proses) }}"/>

<script type="text/javascript">

	

	var table_barang;
	var table_hasil;
	var tb_no = parseInt(10000);
	var id_masuk;
	$(document).ready(function(){
		table_barang = $("#table_barang").DataTable({
			"paging": false
		});
		table_barang.on( 'order.dt search.dt', function () {
            table_barang.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();

        table_hasil = $("#table_hasil").DataTable({
        	"paging": false
        });
		table_hasil.on( 'order.dt search.dt', function () {
            table_hasil.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
        
        id_masuk = $("[name=id_barangmasuk]").val();

        if(id_masuk != ''){
        	get_edit(id_masuk);
        }
		      
       

	})

	
	function get_edit(id){
		$.ajax({
			url: "{{ url('barangmasuk_atm/get_detailmasuk')}} ",
			type: 'post',
			data: {id : id},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(result){
				if(result.length > 0){
					for(i in result){
						table_hasil.row.add(['<div><center></center></div>',
						'<div id="list_kode'+result[i].id_masuk+'">'+result[i].kode_barang+'</div>',
						'<div id="list_nama'+result[i].id_masuk+'">'+result[i].nama_barang+'</div>',
						'<div id="list_komposisi'+result[i].id_masuk+'">'+result[i].nama_komposisi+'</div>',
						'<div id="list_jumlah'+result[i].id_masuk+'">'+result[i].jumlah+'</div>',
						'<div id="list_namasatuan'+result[i].id_masuk+'">'+result[i].nama_satuan+'</div>',
						'<div>'+result[i].nama_kualitas_proses+'</div>',
						'<div id="list_gudang'+result[i].id_masuk+'">'+result[i].nama_gudang+'</div>',
						'<div id="list_corak'+result[i].id_masuk+'">'+result[i].nama_corak+'</div>',
						'<div>'+result[i].nama_motif+'</div>',
						'<div>'+result[i].nama_kualitas+'</div>',
						'<div>'+result[i].kualitas_dudul+'</div>',
						'<div>'+result[i].nama_kualitas_periksa+'</div>',
						'<div>'+result[i].nama_label+'</div>',
						'<div>'+result[i].nama_cap+'</div>',
						'<div>'+result[i].nama_kemasan+'</div>',
						'<div>'+result[i].nama_kemasansatuan+'</div>',
						'<div>'+result[i].nama_kemasansepuluh+'</div>',
						'<div>'+result[i].nama_kemasanseratus+'</div>',
						'<div>'+result[i].nama_shift+'</div>'
						]).draw(false);
					}
				}else{
					
				}
			}
		})
	}

	$("[name=popup_jumlah]").keyup(function(){
		var jum = parseFloat($("[name=popup_jumlah]").val());
		if(isNaN(jum) || jum == 0 || jum == ''){
			jum = parseFloat(0);
		}
		var nilai = parseFloat($("[name=store_konversi]").val());

		var tot = jum*nilai;
		$("[name=popup_jumlah_konv]").val(tot);
	})

	$("[name=popup_jumlah_konv]").keyup(function(){
		var jum = parseFloat($("[name=popup_jumlah]").val());
		if(isNaN(jum) || jum == 0 || jum == ''){
			jum = parseFloat(0);
		}
		var nilai = parseFloat($("[name=store_konversi]").val());

		var tot = jum*nilai;
		$("[name=popup_jumlah]").val(tot);
	})
</script>
@endsection