@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">Upah produksi Kemasan</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Upah Produksi Kemasan</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li>
		      			<button type="button" class="btn btn-md btn-primary" onclick="modal_cetak($(this))"><i class="fa fa-print"></i> Cetak</button>
		      		</li>
		      	</ul>
	       	</div>
	    </div>
	    <!-- <div class="panel-body">
	    	<a href="{{url('upahproduksi/tambah')}}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a>
	    </div> -->

	    <table class="table datatable-basic table-stripped table_upahproduksikemasan">
	    	<thead>
				<tr>
					<th>No</th>
					<th class="text-center"></th>
					<th>Tanggal</th>
					<th>Nomor</th>
					<th>Tanggal Bayar</th>
					<!-- <th>Workorder</th> -->
					<th>Proses</th>
					<th>Pemroses</th>
					<th>Total</th>
				</tr>
			</thead>
			<tbody>
				 
			</tbody>
	    </table>
	</div>
</div>

<div class="modal fade in" role="dialog" id="modal-cetak-rekap-upah">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Rekap 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('upahproduksi_kemasan/cetak_rekap_upah') }}" target="_blank" id="form-cetak-rekap-upah">
      <div class="modal-body">
        <div class="form-group">
        	<label class="control-label col-sm-12 col-md-2">
        		<input type="radio" name="filter_id" value="id_rekanan" class="styled">
        		Rekanan
        	</label>
        	<div class="col-sm-12 col-md-10">
        		<select class="form-control set_select2" name="id_rekanan">
        			<option value="0">Semua</option>
        		</select>
        	</div>
        </div>
        <div class="form-group">
        	<label class="control-label col-sm-12 col-md-2">
        		<input type="radio" name="filter_id" value="id_pegawai" class="styled" checked="">
        		Pegawai
        	</label>
        	<div class="col-sm-12 col-md-10">
        		<select class="form-control set_select2" name="id_pegawai">
        			<option value="0">Semua</option>
        		</select>
        	</div>
        </div>
        <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 set_select2" 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 Bayar</label>
        	<div class="col-sm-12 col-md-5">
        		<input type="text" name="tanggal_awal" class="form-control set_datepicker" value="{{ date('d/m/Y') }}" readonly="" required="">
        	</div>
        	<div class="col-sm-12 col-md-5">
        		<input type="text" name="tanggal_akhir" class="form-control set_datepicker" value="{{ date('d/m/Y') }}" readonly="" required="">
        	</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">Cetak</button>
      </div>
  	</form>

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

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

	$(document).ready(function(){
		$(".set_select2").select2();
		$(".set_datepicker").datepicker({
			format : "dd/mm/yyyy",
			autoclose : true,
			zOfIndex : 9999,
		});

		tb = $(".table_upahproduksikemasan").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('upahproduksi_kemasan/get_data') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},	            
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'nomor', name: 'nomor'},
	            {data: 'tanggal_bayar', name: 'tanggal_bayar'},
	            // {data: 'workorder', name: 'workorder'},
	            {data: 'proses', name: 'proses'},
	            {data: 'pemroses', name: 'pemroses'},
	            {data: 'total', name: 'total'},
	        ],
	        createdRow: function(row, data, index) {
                $('td', row).eq(7).html(accounting.formatMoney(data.total)).attr('align','right'); // 6 is index of column
            }
		});

		// select data pegawai
		$.ajax({
			type : "post",
			url : "{{ url('upahproduksi_kemasan/get_data_pegawai') }}",
			dataType : "json",
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success : function(result){
				$.each(result, function (id, item) {
					var newOption = new Option(item.nomor_pegawai+" - "+item.nama_pegawai, item.id_pegawai, true, true);
					$("#form-cetak-rekap-upah select[name=id_pegawai]").append(newOption).trigger("change");
				});
				$("#form-cetak-rekap-upah select[name=id_pegawai]").val(0).trigger("change");

			}
		});

		// select data rekanan
		$.ajax({
			type : "post",
			url : "{{ url('upahproduksi_kemasan/get_data_rekanan') }}",
			dataType : "json",
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success : function(result){
				$.each(result, function (id, item) {
					var newOption = new Option(item.nama, item.id_rekanan, true, true);
					$("#form-cetak-rekap-upah select[name=id_rekanan]").append(newOption).trigger("change");
				});
				$("#form-cetak-rekap-upah select[name=id_rekanan]").val(0).trigger("change");

			}
		});

		// select data proses
		$.ajax({
			type : "post",
			url : "{{ url('upahproduksi_kemasan/get_data_proses') }}",
			dataType : "json",
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success : function(result){
				var newOption = "";
				$.each(result, function (id, item) {
					if(item.parent>0){
					newOption = new Option(item.nama_proses, item.id_proses, false, false);
					$("#form-cetak-rekap-upah select[name=id_proses]").append(newOption);
					
					newOption = new Option(item.nama_proses, item.id_proses, false, false);
					$("#form_cetak_upah select[name=id_proses]").append(newOption);
					}
				});

				$("#form-cetak-rekap-upah select[name=id_proses]").val(0).trigger("change");
				$("#form_cetak_upah select[name=id_proses]").val(0).trigger("change");

			}
		});
		
	})

	function modal_cetak(this_) {
		showModal($("#modal-cetak-rekap-upah"));
	}

	function hapus(id){
		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('upahproduksi_kemasan/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						tb.ajax.reload();
					}
				})
		 	}
		})
	}


</script>
@endsection