@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="{{ url('hutang') }}"><i class="icon-home2 position-left"></i> Hutang</a></li>
			<li class="active">Daftar Bayar Tagihan</li>
		</ul>
	</div>
</div>

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

	    <div class="panel-body">
	    	<div class="col-md-12">
				@if(Session::has('flash_message_error'))
				<div class="alert alert-error alert-block">
					<button type="button" class="close" data-dismiss="alert">x</button>
					<strong>{!! session('flash_message_error') !!}</strong>
				</div>
				@endif
				@if(Session::has('flash_message_success'))
				<div class="alert alert-success alert-block">
					<button type="button" class="close" data-dismiss="alert">x</button>
					<strong>{!! session('flash_message_success') !!}</strong>
				</div>
				@endif
			</div>
	    	<form class="form-horizontal" method="get" action="#">
	    	
	    	<div class="col-sm-12 col-md-12">
	    		<div class="row col-sm-6 col-md-6">
		    		<div class="form-group">
		    			{{ Form::label("Label CV", "", ['class'=>'control-label col-sm-4']) }}
		    			<div class="col-sm-8">
		    				<div class="checkbox">
		    					<label>
			    					{{ Form::checkbox("cv", '1', ($order_service->cv==1) ? "true":"false", ['class'=>'styled', 'disabled'=>'disabled']) }}
		    					</label>
		    				</div>
		    			</div>
		    		</div>
		    	</div>
	    	</div>
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Penyedia</label>
        			<div class="col-sm-8">
        				{{ Form::text("penyedia", $order_service->nama_penyedia, ['class'=>'form-control', 'readonly'=>'']) }}
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Input</label>
        			<div class="col-sm-8">
        				{{ Form::text("tanggal", date_db($order_service->tanggal, true), ['class'=>'form-control', 'readonly'=>'']) }}
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Order Service</label>
        			<div class="col-sm-8">
        				{{ Form::text("tanggal_nota", date_db($order_service->tanggal_nota, true), ['class'=>'form-control', 'readonly'=>'']) }}
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">No. Order Service</label>
        			<div class="col-sm-8 col-md-8">
        				{{ Form::text("no_nota", $order_service->no_nota."".$order_service->sufix_no_nota, ['class'=>'form-control', 'readonly'=>'']) }}
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Keterangan</label>
        			<div class="col-sm-8">
        				{{ Form::textarea("keterangan", $order_service->keterangan, ['class'=>'form-control', 'rows'=>5, 'readonly'=>'']) }}
        			</div>
        		</div>
        	</div>

        	<div class="col-sm-6">
        		<div class="alert alert-info">
        			<table class="table">
        				<tbody>
        					<tr style="font-size: 20px;">
        						<th width="25%">Pembayaran</th>
        						<th class="text-right">{{ "Rp".rupiah2($order_service->nominal_bayar, 2) }}</th>
        					</tr>
        					<tr>
        						<td>Tagihan</td>
        						<td class="text-right">{{ "Rp".rupiah2($order_service->nominal_netto, 2) }}</td>
        					</tr>
        					<tr style="font-size: 15px;">
        						<th class="text-left">Sisa Tagihan</th>
        						<th class="text-right">{{ "Rp".rupiah2($order_service->nominal_netto-$order_service->nominal_bayar, 2) }}</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 modal-cetak" id="cetak-buktibayar"  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="{{ url('order_service/cetak_bukti_bayar') }}" id="form-cetak-buktibayar" 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::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-buktibayar">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('order_service/tabel_daftar_bayar/'.$order_service->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 loadDaftarBayar() {
	tabelDaftarBayar = $("#tabel-daftar-bayar").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('order_service/tabel_daftar_bayar/'.$order_service->id) }}',
	        columns: [
	            {data: 'tgl_bayar', name: 'tgl_bayar'},
	            {data: 'no_transaksi_bayar', name: 'no_transaksi_bayar'},
	            {data: 'akun_bayar', name: '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_belibayar);
	        	$("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('order_service/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 btnCetakBuktiBayar(this_) {
	var id = this_.parents('tr').data('id');console.log(id);
	// var href = this_.data("href");
	// $("#form-cetak-buktibayar").attr("action", href);
	$("#form-cetak-buktibayar").find("input[name=tanggal_cetak]").val('{{date("d-m-Y")}}');

	var row_data = tabelDaftarBayar.row(this_.parents("tr")).data();
	// console.log(row_data);
	var set_tgl_bayar = moment(row_data.tgl_bayar, "YYYY-MM-DD").format("DD-MM-YYYY");
	$("#form-cetak-buktibayar input[name=id]").val(id);
	$("#form-cetak-buktibayar input[name=tanggal_cetak]").val(set_tgl_bayar).datepicker("setDate", set_tgl_bayar);
	$(".text-no-transaksi").html(row_data.no_transaksi_bayar);
	$(".text-tanggal-transaksi").html(set_tgl_bayar);

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

@endsection