@extends('layout')

@section('content')
<style type="text/css">
.table_td_align_top > tbody > tr > td{
	vertical-align : top;
}
</style>
<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Keuangan</a></li>
			<li><a href="#">Kasbon Pegawai</a></li>
			<li class="active">Daftar Bayar Kasbon</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Daftar Pembayaran Kasbon</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('piutang_pegawai') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      	</ul>
	       	</div>
	    </div>

	    <div class="panel-body">
	    	<form class="" method="get" action="#">

	    	<div class="col-sm-6 col-md-6">
	    		<div class="col-sm-12 col-md-12">
	    			<!-- <div class="col-sm-12 col-md-12"> -->
	    				<div class="form-group">
	    					{{ Form::label("Pegawai", "", ['class'=>'control-label']) }}
	    					{{ Form::text("pegawai", $piutang->nomor_pegawai." - ".$piutang->nama_pegawai, ['class'=>'form-control', 'readonly'=>''])}}
	    				</div>
	    			<!-- </div> -->
	    		</div>
	    		<!-- <div class="col-sm-12 col-md-12"> -->
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
		    				{{ Form::label("No. Transaksi", "", ['class'=>'control-label']) }}
		    				{{ Form::text("nomor_transaksi", $piutang->nomor_transaksi, ['class'=>'form-control', 'readonly'=>'']) }}
		    			</div>
	    			</div>
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
		    				{{ Form::label("Tanggal", "", ['class'=>'control-label']) }}
		    				{{ Form::text("tanggal_transaksi", date_format(date_create($piutang->tanggal_transaksi), "d/m/Y"), ['class'=>'form-control', 'readonly'=>'']) }}
		    			</div>
	    			</div>
	    		<!-- </div> -->
	    		<!-- <div class="col-sm-12 col-md-12"> -->
	    			<div class="col-sm-12 col-md-12">
	    				<div class="form-group">
		    				{{ Form::label("Untuk Keperluan", "", ['class'=>'control-label']) }}
		    				{{ Form::text("keterangan", isset($piutang) ? $piutang->keterangan : "-", ['class'=>'form-control', 'readonly'=>'']) }}
		    			</div>
	    			</div>
	    		<!-- </div> -->
	    	</div>

        	<div class="col-sm-6">
        		<div class="alert alert-info">
        			<table class="table">
        				<tbody>
        					@php
        					$sisa_kasbon = $piutang->nominal-$piutang->total_bayar;
        					@endphp
        					<tr style="font-size: 20px;">
        						<th class="text-left" width="50%">Pembayaran</th>
        						<th class="text-right">{{ "Rp".rupiah2($piutang->total_bayar, 2) }}</th>
        					</tr>
        					<tr>
        						<td>Tagihan</td>
        						<td class="text-right">{{ "Rp".rupiah2($piutang->nominal, 2) }}</td>
        					</tr>
        					<tr style="font-size: 15px;">
        						<th class="text-left">Sisa Tagihan Kasbon</th>
        						<th class="text-right">{{ "Rp".rupiah2($sisa_kasbon, 2) }}</th>
        					</tr>
        					<tr>
        						<th class="text-left">&nbsp;</th>
        						<th class="text-right">
        							@if($sisa_kasbon!=0)
        							<a href="{{ url('piutang_pegawai/'.$piutang->id.'/bayar') }}" class="btn btn-xs btn-success"><i class="icon-cash2"></i> Bayar</a>
        							@else
        							&nbsp;
        							@endif
        						</th>
        					</tr>
        				</tbody>
        			</table>
        		</div>
        	</div>

	    	</form>

	    </div>

			<table class="table" id="tabel-daftar-bayar">
				<thead>
					<tr>
						<th>Tanggal</th>
						<th>No. Transaksi</th>
						<th>Akun Bayar</th>
						<th>Total Bayar</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
		
		<div class="panel-footer">

		</div>

	</div>
</div> <!-- end : .content -->

<!---Modal--->
<div class="modal fade" id="cetak-buktitransaksi"  role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-sm" role="document">
	    <div class="modal-content">
	    	<div class="modal-header with-border">
	    		<h5 class="modal-title" id="exampleModalLabel">Cetak</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      		<form class="form-horizontal" autocomplete="off" method="get" action="#" id="form-cetak-buktitransaksi" target="_blank">
	      	<div class="modal-body">
	      			<div class="form-group">
	      				{{ Form::label("No. Transaksi", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-no-transaksi"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Tanggal", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-tanggal-transaksi"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Pegawai", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-supplier-transaksi"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::hidden("id", 0) }}
		    			{{ Form::label("Label CV", "", ['class'=>'control-label col-sm-4']) }}
		    			<div class="col-sm-8">
		    				<div class="checkbox">
		    					<label>
			    					{{ Form::checkbox("label_cv", 'true', true, ['class'=>'styled']) }}
		    					</label>
		    				</div>
		    			</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Ukuran Kertas", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					{{ Form::select("uk_kertas", ['2'=>'Sedang','1'=>'Kecil'], 2, ['class'=>'form-control']) }}
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Set Tanggal Cetak", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					{{ Form::text("tanggal_cetak", "", ['class'=>'form-control datepicker']) }}
	      				</div>
	      			</div>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="reset" class="btn btn-default" data-dismiss="modal" id="btn-batal-cetak-buktitransaksi">Batal</button>
	        	<button type="submit" class="btn btn-primary" >Cetak</button>
	      	</div>
	      		</form>
	    </div>
	</div>
</div>

<script type="text/javascript">
	var tabelDaftarBayar;
$(document).ready(function () {
	loadDaftarBayar();
});

function loadDaftarBayar() {
	tabelDaftarBayar = $("#tabel-daftar-bayar").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('piutang_pegawai/tabel_daftar_bayar/'.$piutang->id) }}',
	        columns: [
	            {data: 'tgl_bayar', name: 'tgl_bayar'},
	            {data: 'no_transaksi_bayar', name: 'no_transaksi_bayar', render:function(row, type, data, meta){
	            	return data.data_transaksi_bayar.no_transaksi_bayar;
	            }},
	            {data: 'id_akun', name: 'id_akun', render:function(row, type, data, meta){
	            	return data.akun_bayar;
	            }},
	            {data: 'jum_bayar', name: 'jum_bayar'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        createdRow: function(row, data, index) {
	        	$( row ).attr("data-id", data.id);
	        	$("td", row).eq(3).addClass("text-right").text(accounting.formatMoney(data.jum_bayar));
                    
            },
		});
}

function btnHapusDetailBayar(this_) {
	var id = this_.parents("tr").data("id");
	this_.attr("disabled", "");
	swal({
			title: 'Anda yakin akan menghapus data ini?',
			text: 'Menghapus data ini akan mempengaruhi data transaksi keuangan Anda.',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('piutang_pegawai/delete_detail_bayar') }}",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						location.reload();
					}
				})
		 	}else{
				this_.removeAttr("disabled");
		 	}
		})
}

function btnPrintBuktiTransaksi(this_) {
	var id = this_.parents('tr').data('id');
	var href = this_.data("href");
	$("#form-cetak-buktitransaksi").attr("action", href);
	$("#form-cetak-buktitransaksi").find("input[name=tanggal_cetak]").val('{{date("d-m-Y")}}');

	var row_data = tabelDaftarBayar.row(this_.parents("tr")).data();
	var data_transaksi_bayar = row_data.data_transaksi_bayar;
	console.log(data_transaksi_bayar);
	var set_tanggal_transaksi = moment(data_transaksi_bayar['tanggal_bayar'], "YYYY-MM-DD").format("DD-MM-YYYY");
	$("#form-cetak-buktitransaksi input[name=id]").val(id);
	$("#form-cetak-buktitransaksi input[name=tanggal_cetak]").val(set_tanggal_transaksi).datepicker("setDate", set_tanggal_transaksi);
	$(".text-no-transaksi").html(data_transaksi_bayar['no_transaksi_bayar']);
	$(".text-tanggal-transaksi").html(set_tanggal_transaksi);
	$(".text-supplier-transaksi").html('{{$piutang->nama_pegawai}}');

	showModal($("#cetak-buktitransaksi"));
}
</script>

@endsection