@extends('layout')


@section('content')

<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 class="active">Retur Tagihan Piutang Awal</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">Retur Tagihan Piutang Awal</h5>

			<div class="heading-elements">
		      	<a href="{{ route('rtp.addPiutangAwal') }}" class="btn btn-xs btn-primary"><i class="icon-plus2"></i> Tambah</a>
	       	</div>
	    </div>
	    <div class="panel-body">


	    <table class="table datatable-basic table-striped table_retur_tagihan_piutang">
	    	<thead>
				<tr>
					<th class="text-center">Tanggal Retur</th>
					<th class="text-center">No. Retur</th>
					<th class="text-center">No. Faktur</th>
					<th class="text-center">Nominal Retur</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>

			</tbody>
	    </table>
	    
	    </div>
	</div>
</div>

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

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

	function loadTable()
	{
		table = $(".table_retur_tagihan_piutang").DataTable({
			processing: true,
	        serverSide: true,
	        deferRender: true,
	        ajax: '{{ route('rtp.getDataPiutangAwal') }}',
	        columns: [
	            {data: 'tanggal_retur', name: 'tanggal_retur', render : function(tanggal_retur){
	            	return moment(tanggal_retur).format("DD-MM-YYYY");
	            }},
	            {data: 'no_retur', name: 'nomor_retur'},
	            {data: 'no_faktur', name: 'nomor_faktur'},
	            {data: 'nominal_retur', name: 'nominal_retur'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        order : false,
	        createdRow: function(row, data, index) {
				$( row ).attr('data-id', data['id_rtp']);
				$( 'td', row ).eq(3).html(changeCurrency(data.nominal_retur, data.mata_uang)).addClass('text-right');
				$( 'td', row ).eq(4).addClass('text-center');
            }
		});
	}

	function deleteRetur(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('retur-tagihan-piutang-awal/delete/')}}/"+id,
					type: 'get',
					success: function(response){
						if (response.status == "Success") {
							table.ajax.reload();
							Swal.fire(
							  'Berhasil!',
							  'Data berhasil dihapus.',
							  'success'
							)
						} else {
							Swal.fire(
							  'Gagal!',
							  'Data gagal dihapus.',
							  'error'
							)
						}
					}
				})
		 	}
		})
	}
</script>

@endsection