@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> Keuangan</a></li>
			<li class="active">Piutang</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</h5>

			<div class="heading-elements">
		      	<!-- <a href="{{ url('piutang/piutang_awal') }}" class="btn btn-xs btn-success"><i class="icon-plus2"></i> Tambah</a> -->
		      	<a href="{{ url('piutang/laporan-piutang-penjualan') }}" type="button" class="btn btn-success"><i class="icon-printer"></i>&nbsp;Piutang Penjualan</a>
	       	</div>
	    </div>
	    <div class="panel-body">


	    <table class="table datatable-basic table-striped table_piutang">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Tanggal</th>
					<th>No. Faktur</th>
					<th>Pelanggan</th>
					<th>Jatuh Tempo</th>
                    <th>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 tabelPiutang;

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

		$("#btn_tambah_barang").click(function(){
			$("#exampleModal").modal("show");
		})

	});

	function loadTabelPiutang() {
		tabelPiutang = $(".table_piutang").DataTable({
			processing: true,
	        serverSide: true,
	        deferRender: true,
	        searchDelay : 2000,
	        ajax: '{{ url('piutang/get_data') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'tanggal_faktur', name: 'tanggal_faktur', render : function(tanggal_faktur){
	            	return moment(tanggal_faktur).format("DD-MM-YYYY");
	            }},
	            {data: 'no_faktur', name: 'nomor_faktur'},
	            {data: 'nama_pelanggan', name: 'nama_pelanggan'},
	            {data: 'tanggal_tempo', name: 'tanggal_tempo', render : function(tanggal_tempo){return moment(tanggal_tempo).format("DD-MM-YYYY");
	            }},
	            {data: 'tagihan', name: 'tagihan'},
	            {data: 'pembayaran', name: 'pembayaran'},
	            {data: 'set_status', name: 'set_status'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        order : false,
	        createdRow: function(row, data, index) {
				$( row ).attr('data-id', data['id_penjualan']);
				$( 'td', row ).eq(5).html(changeCurrency(data.tagihan, data.mata_uang)).addClass('text-right');
				$( 'td', row ).eq(6).html(changeCurrency(data.pembayaran, data.mata_uang)).addClass('text-right');
                $('td', row).eq(7).attr('nowrap','');
            },
		});
	}

	function edit_satuan(){
		$("#exampleModal").modal("show");
	}
</script>

@endsection