@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><i class="icon-home2 position-left"></i> Master</li>
			<li class="active">Upah Tenun</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Upah Tenun</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('upahtenun/tambah')}}" class="btn btn-primary">Tambah</a>
	    </div>
	    <table class="table table-striped tabel_upah">
	    	<thead>
				<tr class="text-center">
					<th rowspan="2">No</th>
					<th rowspan="2">Tanggal</th>
					<th rowspan="2">Motif</th>
					<th rowspan="2">Tenun</th>
					<th rowspan="2">Makelar</th>
					<th rowspan="2">Total</th>
					<th colspan="3">Potongan</th>
					<th rowspan="2">Aksi</th>
				</tr>
				<tr>
					<th>Kualitas D</th>
					<th>Kualitas N</th>
					<th>Kualitas BS</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
	</div>
</div>



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

	$(document).ready(function(){
		loadTabelUpahtenun();

	});

	function loadTabelUpahtenun() {
		tabel_upah = $(".tabel_upah").DataTable({
			processing: true,
	        serverSide: true,
	        filter : false,
	        ajax: '{{ url('upahtenun/get_upahtenun') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'tanggal_berlaku', name: 'tanggal_berlaku', render : function(tanggal_berlaku){
	            	return moment(tanggal_berlaku).format("DD-MM-YYYY");
	            }},
	            {data: 'nama_motif', name: 'nama_motif'},
	            {data: 'nominal_rekanan', name: 'nominal_rekanan'},
	            {data: 'nominal_rekanan_kelompok', name: 'nominal_rekanan_kelompok'},
	            {data: 'nominal_total', name: 'nominal_total'},
	            {data: 'potongan_d', name: 'potongan_d'},
	            {data: 'potongan_n', name: 'potongan_n'},
	            {data: 'potongan_bs', name: 'potongan_bs'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        createdRow : function(row, data, index){
	        	$( row ).attr("data-id", data.id);
	        	var n = 2;
	        	$("td", row).eq(n+1).addClass(".text-right").html(accounting.formatMoney(data.nominal_rekanan));
	        	$("td", row).eq(n+2).addClass(".text-right").html(accounting.formatMoney(data.nominal_rekanan_kelompok));
	        	$("td", row).eq(n+3).addClass(".text-right").html(accounting.formatMoney(data.nominal_total));
	        	$("td", row).eq(n+4).addClass(".text-right").html(accounting.formatMoney(data.potongan_d));
	        	$("td", row).eq(n+5).addClass(".text-right").html(accounting.formatMoney(data.potongan_n));
	        	$("td", row).eq(n+6).addClass(".text-right").html(accounting.formatMoney(data.potongan_bs));

	        }
		});
	}

	function btnHapusUpahtenun(this_){
		var id = this_.parents("tr").data("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('upahtenun/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers: {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					dataType: 'json',
					complete: function(respon){
						var set = respon.responseJSON;
						swal(set.pesan, "", set.notif);
						tabel_upah.ajax.reload();
					}
				})
		 	}
		})
	}	
</script>

@endsection