@extends('layout')


@section('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> Produksi</a></li>
			<li class="active">Borongan Lainnya </li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Daftar Upah Borongan Langsung</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<a class="btn btn-primary" id="btn_tambah" href="{{ url('upah_produksitanpahasil/tambah') }}"><i class=""></i>Tambah</a>
	    </div>

	    <table class="table table-stripped table_upah" id="">
	    	<thead>
				<tr>
					<th class="text-center">No</th>
					<th class="text-center"></th>
					<th class="text-center">Nomor Upah</th>
					<th class="text-center">Tanggal</th>
					<th class="text-center">Tanggal Bayar</th>
					<th class="text-center">Nama</th>
					<th class="text-center">Bagian</th>
					<th class="text-center">Lokasi</th>
					<th class="text-center">Upah</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
	</div>
</div>

<div class="modal fade in" role="dialog" id="modal_cetak_upah">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="title_upah">Cetak Slip Upah</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
    
      <form class="form-horizontal" method="get" action="{{ url('upah_produksitanpahasil/cetak') }}" target="_blank" id="form_cetak_upah">
      <div class="modal-body">
      	<input type="hidden" name="id_upahproduksi" id="id_upahproduksi">
      	<input type="hidden" name="nomor" id="nomor">
      	<input type="hidden" name="jenis" id="jenis">
      	<input type="hidden" name="idrekanan" id="idrekanan">
      	<input type="hidden" name="idpegawai" id="idpegawai">

        <div class="form-group">
        	<label class="control-label col-sm-12 col-md-2">
        		Pemroses
        	</label>
        	<div class="col-sm-12 col-md-10">
        		<p class="form-control-static" id="nama_pemroses">
	        		Pemroses
	        	</p>
        	</div>
        </div>

        <div class="form-group">
        	<label class="control-label col-sm-12 col-md-2">
        		Berdasarkan
        	</label>
        	<div class="col-sm-12 col-md-10 control-label">
        		<div class="row">
        			<div class="col-sm-12 col-md-3">
        				<input type="radio" name="filter_cetak" value="nomor" class="styled" checked> Nomor Upah
        			</div>
        			<div class="col-sm-12 col-md-3">
        				<input type="radio" name="filter_cetak" value="pemroses" class="styled"> Pemroses
        			</div>
        		</div>
        	</div>
        </div>

        <div id="text_nomor_upah">
        	<div class="form-group">
        		<label class="control-label col-sm-12 col-md-2">Nomor Upah</label>
        		<div class="col-sm-12 col-md-10">
        			<p class="form-control-static" style="font-weight: bold;" id="set_text_nomor_upah">...</p>
        		</div>
        	</div>
        </div>

        <div style="display: none;" id="range_tgl">
	        <div class="form-group">
	        	<label class="control-label col-sm-12 col-md-2">
	        		Proses
	        	</label>
	        	<div class="col-sm-12 col-md-10">
	        		<select class="form-control select-search" name="id_proses">
	        			{{-- <option value="0">Semua</option> --}}
	        		</select>
	        	</div>
	        </div>
        	<div class="form-group">
	        	<label class="control-label col-sm-12 col-md-2">Tgl. Upah</label>
	        	<div class="col-sm-12 col-md-4">
	        		<input type="text" name="tgl_awal" class="form-control datepicker" value="{{ date('d-m-Y') }}" readonly="" required="">
	        	</div>
	        	<label class="control-label col-sm-1 col-md-1">sampai</label>
	        	<div class="col-sm-12 col-md-4">
	        		<input type="text" name="tgl_akhir" class="form-control datepicker" value="{{ date('d-m-Y') }}" readonly="" required="">
	        	</div>
	        </div>
	        <div class="form-group">
	        	<label class="control-label col-sm-12 col-md-2">&nbsp;</label>
	        	<div class="col-sm-12 col-md-10">
		        	<?php
		        	$arr_opt = ["1"=>"Rekap", "2"=>"Detail"];
		        	?>
		        	<select class="form-control select-search" name="tipe_laporan">
		        		@foreach($arr_opt AS $key=>$value)
		        		<option value="{{$key}}">{{$value}}</option>
		        		@endforeach
		        	</select>
		        </div>
	        </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
        <button type="submit" class="btn btn-primary">Tampilkan</button>
      </div>
  	</form>

    </div>
  </div>
</div>



<script type="text/javascript">
	var tb;

	$(document).ready(function(){
		tb = $(".table_upah").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('upah_produksitanpahasil/get_data') }}',
	        columns: [
	            {data: 'id_upah', name: 'id_upah', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
			  	{data: 'aksi', name: 'aksi', orderable: false, searchable: false},
	            {data: 'nomor', name: 'nomor'},
	            {data: 'tanggal_upah', name: 'tanggal_upah'},
	            {data: 'tanggal_bayar', name: 'tanggal_bayar'},
	            {data: 'pemroses', name: 'pemroses'},
	            {data: 'nama_proses', name: 'nama_proses'},
	            {data: 'lokasi', name: 'lokasi', className:'text-center'},
	            {data: 'jumlah', name: 'jumlah'}
	        ],
	        createdRow: function(row, data, index){
	        	$('td', row).eq(8).html(accounting.formatMoney(data.jumlah)).attr('align','right'); // 6 is index of column
	        }
		});

		get_data_proses();
	})

	function cetak(this_){
		var id_upah = $(this_).attr('id_upah');
		var pemroses = $(this_).attr('pemroses');
		var nomor = $(this_).attr('nomor_upah');
		var id_rekanan = $(this_).attr('id_rekanan');
		var id_pegawai = $(this_).attr('id_pegawai');

		$("#idrekanan").val(id_rekanan);
		$("#idpegawai").val(id_pegawai);
		$("#id_upahproduksi").val(id_upah);
		$("#nama_pemroses").text(pemroses);
		$("#set_text_nomor_upah").text(nomor);


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

	function get_data_proses(){
		$.ajax({
			url: "{{ url('upah_produksitanpahasil/get_data_proses') }}",
			type: 'get',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				$.each(respon, function (id, item){
					if(item.parent>0){
						newOption = new Option(item.nama_proses, item.id_proses, false, false);
						$("#form_cetak_upah select[name=id_proses]").append(newOption);
					}
				});
			}
		})
	}

	function hapus(id){
		swal({
			title: 'Anda yakin akan menghapus data ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('upah_produksitanpahasil/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						if (respon.status == "Success") {
							tb.ajax.reload();
						} else {
							alert('Gagal menghapus data!');
						}
					}
				})
		 	}
		})
	}
	
	$("[name=filter_cetak]").change(function(evt){
		evt.preventDefault();
		if ($(this).val() == "pemroses") {
			$("#range_tgl").show();
			$("#text_nomor_upah").hide();
		}else{
			$("#range_tgl").hide();
			$("#text_nomor_upah").show();
		}
	})
</script>

@endsection