@extends('layout')

@section('js_script')
@endsection

@section('content')
<style type="text/css">
	.details-control{
		cursor: pointer;
	}
</style>

<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> Laporan</a></li>
			<li class="active">Neraca Saldo</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Neraca Saldo</h5>
	    </div>
	    <div class="panel-body">
	    	<div class="row">
	    		<div class="col-sm-8 col-md-8">
			    	<form class="form" method="get" action="" id="form-filter-neraca-saldo">
			    		<div class="form-group">
			    			{{ Form::label("Tanggal", "", ['class'=>'control-label col-sm-2 col-md-2']) }}
			    			<div class="col-sm-3 col-md-3" >
				    			{{ Form::text("tanggal_awal", date("d-m-Y"), ['class'=>'form-control set_datepicker','id'=>'tanggal_awal']) }}
				    		</div>
			    			<div class="col-sm-3 col-md-3" >
				    			{{ Form::text("tanggal_akhir", date("d-m-Y"), ['class'=>'form-control set_datepicker','id'=>'tanggal_akhir']) }}
				    		</div>
			    			<div class="col-sm-3 col-md-3 btn-group">
				    			<button type="submit" class="btn btn-sm btn-info">
				    				<i class="fa fa-filter"></i> Filter
				    			</button>
				    			<a href="javascript:void(0)" id="btn_excel" class="btn btn-sm btn-success"><i class="fa fa-file-excel-o"></i> Excel</a>
				    		</div>
			    		</div>
			    		<!-- <div class="form-group">
			    			{{ Form::label("", "", ['class'=>'control-label col-sm-2 col-md-2']) }}
    			    		<div class="col-sm-3 col-md-3 btn-group">
    					    	<a href="javascript:void(0)" id="btn_excel" class="btn btn-sm btn-success"><i class="fa fa-file-excel-o"></i> Excel</a>
    			    		</div>
			    		</div> -->
			    	</form>	
	    		</div>

	    		<!-- <div class="col-sm-4 col-md-4">
			    	<form class="form" action="#">
			    		<div class="form-group">
			    			<div class="col-sm-12 col-md-12 text-right">
							
							</div>
						</div>
					</form>
	    		</div> -->
	    		
	    		<div class="col-sm-12 col-md-12" style="margin-top: 2%;" id="div-tabel-neraca-saldo">
		    		<div class="table-responsive">	
		    			<table class="table table-stripped" id="tabel-neraca-saldo">
		    				<thead>
		    					<tr>
		    						<th>Kode</th>
		    						<th>Akun</th>
		    						<th>Debet</th>
		    						<th>Kredit</th>
		    					</tr>
		    				</thead>
		    				<tbody>

		    				</tbody>
		    				<tfoot>

		    				</tfoot>
		    			</table>
		    		</div>
	    		</div>

	    	</div> <!-- end : row -->
	    </div>
	</div>
</div>

<script type="text/javascript">
	var table;
	var urlParam;
	var urlData;

	var arr_key = [];
	var arr_detail = [];
	var base_url = "{{ url('/') }}";

	function isNegative(number) {
		if (parseFloat(number) < 0) {
			return "("+currency.format(Math.abs(parseFloat(number)))+")";
		} else {
			return currency.format(parseFloat(number));
		}
	}

	var currency = new Intl.NumberFormat('de-DE', { 
        // style: 'currency', 
        // currency: 'IDR', 
        minimumFractionDigits: 2, 
    });

$(document).ready(function(){
	$(".set_datepicker").datepicker({
		format : "dd-mm-yyyy",
		autoclose : true,
      	zIndexOffset : 9999,
	});

	urlParam = getUrlParams();
	urlData = '{{ url("laporan/get_data_neraca_saldo") }}';

	if(Object.keys(urlParam).length > 1){
		urlData += '?tanggal_awal='+urlParam['tanggal_awal']+'&tanggal_akhir='+urlParam['tanggal_akhir'];
	} else {
		urlData += '?tanggal_awal='+$("#tanggal_awal").val()+'&tanggal_akhir='+$("#tanggal_akhir").val();
	}
	
	table = $('#tabel-neraca-saldo').DataTable({
		serverSide : true,
		processing : true,
		deferRender : true,
		searchDelay: 1500,
		ajax : urlData,
		columns : [
			{data:'kode_perkiraan', name:'kode_perkiraan'},
			{data:'nama_perkiraan', name:'nama_perkiraan'},
			{data:'D', name:'D'},
			{data:'K', name:'K'},
		],
		order : false,
		scrollX : true,
		createdRow : function(row, data, index){
			arr_key.push(data.kode_perkiraan);
			arr_detail.push(data.detail);

			// $("td", row).addClass('details-control');
			// $("td", row).eq(2).addClass('text-right').html(accounting.formatMoney(data['D']));
			$("td", row).eq(2).addClass('text-right').html(isNegative(data['D']));
			// $("td", row).eq(3).addClass('text-right').html(accounting.formatMoney(data['K']));
			$("td", row).eq(3).addClass('text-right').html(isNegative(data['K']));
		}
	});

});

	$("#btn_excel").click(function(evt){
		window.open(base_url+'/laporan/neraca_saldo/excel?tanggal_awal='+$("#tanggal_awal").val()+'&tanggal_akhir='+$("#tanggal_akhir").val());
	})

</script>

@endsection