<?php $__env->startSection('content'); ?>

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Inventori</a></li>
			<li class="active">Penerimaan Barang Produksi</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Penerimaan Barang Produksi</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>

	    <table class="table table-stripped dataTable">
	    	<thead>
				<tr>
					<th>No</th>
					<th>No. Pembelian</th>
					<th>No. Penerimaan</th>
					<th>Tanggal</th>
					<th>Penyedia</th>
					<th>Lokasi Pembelian</th>
					<th>Status Penerimaan</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>
								
			</tbody>
	    </table>
	</div>
</div>

<div class="modal fade" id="exampleModal"  role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg" role="document">
	    <div class="modal-content">
	    	<div class="modal-header">
	    		<h5 class="modal-title" id="exampleModalLabel">Cetak Bukti</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      	<div class="modal-body">
	      		<form class="form-horizontal" autocomplete="off" method="post" target="_blank" id="form_cetak">
	      			<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
	      			<input type="hidden" name="popup_id">
	      			<input type="hidden" name="popup_induk">
	      			<table class="table table-stripped">
	      				<tr>
	      					<td width="30%">Tanggal Faktur</td>
	      					<td width="5%">:</td>
	      					<td id="popup_tgl"></td>
	      				</tr>
	      				<tr>
	      					<td>Nomor Faktur</td>
	      					<td>:</td>
	      					<td id="popup_faktur"></td>
	      				</tr>
	      				<tr>
	      					<td>Penyedia</td>
	      					<td>:</td>
	      					<td id="popup_penyedia"></td>
	      				</tr>
	      				<tr>
	      					<td>Jenis Kertas</td>
	      					<td>:</td>
	      					<td>
	      						<select class="form-control select-search" name="popup_ukuran">
	      							<option value="0">Kecil</option>
	      							<option value="1">Sedang</option>	      							
	      						</select>
	      					</td>
	      				</tr>
	      				<tr>
	      					<td></td>
	      					<td colspan="2"></td>
	      				</tr>
	      			</table>
	      			
	      		
	      	</div>
	      	<div class="modal-footer">
	        	<button class="btn btn-primary" type="submit" id="btn_popup_simpan">Cetak</button>
	      	</div>
	      	</form>
	    </div>
	</div>
</div>

<div class="modal fade" id="exampleModal_terima"  role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg" role="document">
	    <div class="modal-content">
	    	<div class="modal-header">
	    		<h5 class="modal-title" id="exampleModalLabel">Detail Penerimaan</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      	<div class="modal-body">
	      		<form class="form-horizontal" autocomplete="off" method="post" target="_blank" id="form_cetak">
	      			<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
	      			<input type="hidden" name="popup_terima_id">
	      			<input type="hidden" name="popup_terima_induk">
	      			<table class="table table-stripped">
	      				<tr>
	      					<td width="30%">Tanggal Faktur</td>
	      					<td width="5%">:</td>
	      					<td id="popup_terima_tgl"></td>
	      				</tr>
	      				<tr>
	      					<td>Nomor Faktur</td>
	      					<td>:</td>
	      					<td id="popup_terima_faktur"></td>
	      				</tr>
	      				<tr>
	      					<td>Penyedia</td>
	      					<td>:</td>
	      					<td id="popup_terima_penyedia"></td>
	      				</tr>
	      				<tr>
	      					<td></td>
	      					<td colspan="2"></td>
	      				</tr>
	      			</table>

	      			<div class="col-sm-12 table-responsive">
	      			<h5>Detail Barang </h5>
	      			<table class="table table-stripped" id="tabel_terima">
	      			<thead>
						<tr>
							<th>No</th>
	      					<th>Nama Barang</th>
	      					<th>Jumlah</th>
	      					<th>Satuan</th>
	      					<th>Status</th>
	      					<th>Aksi</th>
						</tr>
					</thead>
					<tbody>

					</tbody>
	      			</table>
	      		</div>
	      		
	      	</div>
	      	<div class="modal-footer">
	        	
	      	</div>
	      	</form>
	    </div>
	</div>
</div>

<input type="hidden" name="store_idbeli">
<input type="hidden" name="store_induk">

<script type="text/javascript">
	var dataTable;
	var tabel_terima;
	$(document).ready(function(){
		dataTable = $(".dataTable").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '<?php echo e(url('penerimaan/get_data')); ?>',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}, className : 'text-center'},
	            {data: 'faktur', name: 'faktur'},
	            {data: 'no_terima', name: 'no_terima'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'nama_penyedia', name: 'nama_penyedia'},
	            {data: 'nama_lokasi', name: 'nama_lokasi'},
	            {data: 'status', name: 'status',  searchable: false, className : 'text-center'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        "order": [[ 6, "desc" ]]
		});
		
		tabel_terima = $("#tabel_terima").DataTable();
		tabel_terima.on( 'order.dt search.dt', function () {
            tabel_terima.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
	})

	function cetak(this_){
		var url = $(this_).attr('link_data');
		var idbeli = $(this_).attr('idbeli');
		var induk = $(this_).attr('induk');

		console.log(idbeli+" | "+induk);

		$("#form_cetak").attr('action', url);
		$.ajax({
			url: "<?php echo e(url('penerimaan/get_detail')); ?>",
			type: 'get',
			dataType: 'json',
			data: {id_beli : idbeli, induk : induk},
			success: function(respon){
				if(respon.status == 1){
					$("#popup_tgl").text(respon.data.tanggal_faktur);
					$("#popup_faktur").text(respon.data.no_faktur+respon.data.sufix_no_faktur);
					$("#popup_penyedia").text(respon.data.nama_penyedia);
					$("[name=popup_id]").val(respon.data.id_pembelian);
					$("[name=popup_induk]").val(respon.data.id_induk);

					$("#exampleModal").modal('show');
				}
			}
		})
		//
	}

	function popup(this_){
		var id_beli = $(this_).attr('id_beli');
		var induk = $(this_).attr('induk');

		$("[name=store_idbeli]").val(id_beli);
		$("[name=store_induk]").val(induk);
		
		$.ajax({
			url: "<?php echo e(url('penerimaan/get_detail')); ?>",
			type: 'get',
			dataType: 'json',
			data: {id_beli : id_beli, induk : induk},
			success: function(respon){
				if(respon.status == 1){
					$("#popup_terima_tgl").text(respon.data.tanggal_faktur);
					$("#popup_terima_faktur").text(respon.data.no_faktur+respon.data.sufix_no_faktur);
					$("#popup_terima_penyedia").text(respon.data.nama_penyedia);
					$("[name=popup_terima_id]").val(respon.data.id_pembelian);
					$("[name=popup_terima_induk]").val(respon.data.id_induk);

					get_terima(id_beli, induk);

					$("#exampleModal_terima").modal('show');
				}
			}
		})
	}

	function get_terima(id_beli, induk){
		$.ajax({
			url: "<?php echo e(url('penerimaan/get_detail_terima')); ?>",
			type: 'get',
			data: {id_beli : id_beli, induk : induk},
			success: function(respon){
				if(respon.status == '1'){
					tabel_terima.clear().draw();
					
					for(i in respon.data){
						tabel_terima.row.add(['<div><center></center></div>',
							'<div>'+respon.data[i].nama_barang+'</div>',
							'<div>'+respon.data[i].jml_barang_terima+'</div>',
							'<div>'+respon.data[i].nama_satuan+'</div>',
							'<div>'+respon.data[i].status+'</div>',
							'<div>'+respon.data[i].aksi+'</div>'
							]).draw(false);
					}
				}else{
					tabel_terima.clear().draw();
				}
			}
		})
	}

	function verif(this_){
		var id_terima = $(this_).attr('id_terima');
		var status = $(this_).attr('status');
		swal({
			title: 'Anda yakin akan merubah status item ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "<?php echo e(url('penerimaan/batal_terima')); ?>",
					type: 'get',
					data: {id : id_terima, status : status, jenis : '0'},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						if(respon.status == '0'){
							yakin(id_terima, status, '1');
						}else{
							get_terima($("[name=store_idbeli]").val(), $("[name=store_induk]").val());
						}
					}
				})
		 	}
		})
	}

	function yakin(id_terima, status, jenis){
		swal({
			title: 'Dengan merubah 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: "<?php echo e(url('penerimaan/batal_terima')); ?>",
					type: 'get',
					data: {id : id_terima, status : status, jenis : jenis},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						get_terima($("[name=store_idbeli]").val(), $("[name=store_induk]").val());
					}
				})
		 	}
		})
	}

	function hapus(this_){
		var idbeli = $(this_).attr('idbeli');
		var induk = $(this_).attr('induk');
		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: "<?php echo e(url('penerimaan/hapus_terima')); ?>",
					type: 'get',
					data: {idbeli : idbeli, induk : induk},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						dataTable.ajax.reload();
					}
				})
		 	}
		})
	}

	$('#exampleModal_terima').on('hidden.bs.modal', function () {
		dataTable.ajax.reload();
	})
	
</script>


<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>