@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> Piutang Awal</a></li>
			<li class="active"></li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="row">
		<div class="col-lg-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>
	</div>
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Piutang Awal</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('piutangawal/tambah')}}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a>

		    <table class="table table_jual table-stripped">
		    	<thead>
					<tr>
						<th>No</th>
						<th>Tanggal</th>
						<th>No. Faktur</th>
						<th>Pelanggan</th>
						<th>Tgl Jatuh Tempo</th>
	                    <th>Total</th>
	                    <th>Sisa Tagihan</th>
	                    <th>Pembayaran</th>
	                    <th>Status</th>
	                    <th class="text-center"></th>
					</tr>
				</thead>
				<tbody>
				
				</tbody>
		    </table>
	    </div>
	</div>
</div>

<script type="text/javascript">
	var d = new Date();
	var month = d.getMonth()+1;
	var day = d.getDate();
	var output = ((''+day).length<2 ? '0' : '') + day + '-' + ((''+month).length<2 ? '0' : '') + month + '-' + d.getFullYear();

	var table_jual;
	var date_now = 

	$(document).ready(function(){
		loadTabelJual();
	});

	function loadTabelJual() {
		table_jual = $(".table_jual").DataTable({
			serverSide : true,
			processing : true,
			ajax : "{{ url('piutangawal/get_data') }}",
			columns : [
				{data:'id', name:'id', searchable:false, render : function(data, type, full, meta){
					return meta.row+1;
				}},
				{data:'tanggal', name:'tanggal'},
				{data:'no_faktur', name:'no_faktur'},
				{data:'nama_pelanggan', name:'nama_pelanggan'},
				{data:'tanggal_tempo', name:'tanggal_tempo'},
				{data:'total', name:'total', render:function(total){
					return accounting.formatMoney(total);
				}},
				{data:'sisa_tagihan', name:'sisa_tagihan', render:function(sisa_tagihan){
					return accounting.formatMoney(sisa_tagihan);
				}},
				{data:'pembayaran', name:'pembayaran', render:function(pembayaran){
					return accounting.formatMoney(pembayaran);
				}},
				{data:'status', name:'status'},
				{data:'aksi', name:'aksi', searchable:false, orderable:false}
			]
		});
	}

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