@extends('layout')


@section('content')

<style type="text/css">
.modal-cetak .form-group{
	margin-bottom: 5px !important;
}
</style>

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Penjualan</a></li>
			<li class="active">Retur Penjualan (Non Faktur)</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Retur Penjualan (Non Faktur)</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('penjualan/retur-penjualan-nonfaktur/create')}}" class="btn btn-success">Buat Retur</a>
	    </div>

	    @if ($message = Session::get('message'))
		<div class="alert {{ Session::get('classCategori') }} alert-block">
			<button type="button" class="close" data-dismiss="alert">×</button>	
			<strong>{{ $message }}</strong>
		</div>
		@endif

	    <table class="table table_retur_jual table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th class="text-center"></th>
					<th>Tanggal</th>
					<th>No. Retur</th>
					<th>Pelanggan</th>
                    <th>Total</th>
                    <th>Status</th>
				</tr>
			</thead>
			<tbody>
			
			</tbody>
	    </table>
	</div>
</div>

<!---Modal--->
<div class="modal fade modal-cetak" id="cetak_retur_penjualan" 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="#" id="form_cetak_retur_penjualan" target="_blank">
	      	<div class="modal-body">
	      			<div class="form-group">
	      				{{ Form::label("No. Retur", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-no-retur-penjualan"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Tanggal Retur", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-tanggal-retur-penjualan"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Pelanggan", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-pelanggan-penjualan"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Total", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-total"></p>
	      				</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 class="form-group">
	      				{{ Form::label("&nbsp;", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<div class="checkbox">
	      						<label>
	      							{{ Form::checkbox("tampil_harga", "true", true, ['class'=>'styled', 'id'=>'tampil_harga']) }} Tampilkan Harga
	      						</label>
	      					</div>
	      				</div>
	      			</div>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="reset" class="btn btn-default" data-dismiss="modal" id="btn_batal_cetak_pepenjualan">Batal</button>
	        	<button type="submit" class="btn btn-primary" >Cetak</button>
	      	</div>
	      		</form>
	    </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_retur_jual;

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

	function loadTabelRetur() {
		table_retur_jual = $(".table_retur_jual").DataTable({
			serverSide : true,
			processing : true,
			deferRender : true,
			ajax : "{{ url('penjualan/retur-penjualan-nonfaktur/get_data') }}",
			columns : [
				{data:'id', name:'id', searchable:false, render : function(data, type, full, meta){
					return meta.row+1;
				}},
				{data:'aksi', name:'aksi', searchable:false, orderable:false},
				{data:'tanggal_retur', name:'tanggal_retur'},
				{data:'nomor_retur', name:'nomor_retur'},
				{data:'nama_pelanggan', name:'nama_pelanggan'},
				{data:'total_retur', name:'total_retur', searchable:false},
				{data:'set_status', name:'set_status', searchable:false, orderable:false},
			],
			scrollX : true,
			createdRow : function( row, data, dataIndex ) {
				$( row ).attr('data-id', data.id);
				$("td", row).eq(5).addClass("text-right").html(accounting.formatMoney(data.total_retur));
				$("td", row).eq(5).addClass("text-center");
			},
		});
	}

	function btnCetak(this_) {
		var href = this_.data("href");
		$("#form_cetak_retur_penjualan").attr("action", href);
		// $("#form_cetak_retur_penjualan").find("input[name=tanggal_cetak]").val('{{--date("d-m-Y")--}}');

		var row_data = table_retur_jual.row(this_.parents("tr")).data();
		$(".text-no-retur-penjualan").html(row_data.nomor_retur);
		$(".text-tanggal-retur-penjualan").html(row_data.tanggal_retur);
		$(".text-pelanggan-penjualan").html(row_data.nama_pelanggan);
		$(".text-total").html(accounting.formatMoney(row_data.total_retur));

		showModal($("#cetak_retur_penjualan"));
	}

	function btnHapusRetur(this_){
		var id_retur = this_.parents("tr").data("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('penjualan/retur-penjualan-nonfaktur/delete')}}/"+id_retur,
					type: 'post',
					data: {'_method':'delete'},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						if (respon.status == "success") {
							table_retur_jual.ajax.reload();
							Swal.fire(
							  'Berhasil!',
							  'Data berhasil dihapus.',
							  'success'
							)
						} else {
							Swal.fire(
							  'Gagal!',
							  'Data gagal dihapus.',
							  'error'
							)
						}
					}
				})
		 	}
		})
	}

	
</script>
@endsection