@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="index.html"><i class="icon-home2 position-left"></i> Service</a></li>
			<li class="active">Order Service</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Order Service</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('order_service/create')}}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a>
	    </div>

	    <table class="table tabel-order-service table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Lokasi</th>
					<th>Tanggal</th>
					<th>No. Order</th>
					<th>Penyedia</th>
                    <th>Tagihan</th> 
                    <th>Sisa Tagihan</th>
					<th class="text-center"></th>
				</tr>
			</thead>
			<tbody>
			
			</tbody>
	    </table>
	</div>
</div>

<!---Modal--->
<div class="modal fade modal-cetak" id="cetak-orderservice"  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-orderservice" target="_blank">
	      	<div class="modal-body">
	      			<div class="form-group">
	      				{{ Form::label("No. Order Service", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-no-orderservice"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Tanggal", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-tanggal-orderservice"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Supplier", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-supplier-orderservice"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Total Tagihan", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					<p class="form-control-static text-tagihan-orderservice"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				{{ Form::label("Ukuran Kertas", "", ['class'=>'control-label col-sm-4 col-md-4']) }}
	      				<div class="col-sm-8 col-md-8">
	      					{{ Form::select("uk_kertas", ['1'=>'Kecil', '2'=>'Sedang'], 1, ['class'=>'form-control']) }}
	      				</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']) }} 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-orderservice">Batal</button>
	        	<button type="submit" class="btn btn-primary" >Cetak</button>
	      	</div>
	      		</form>
	    </div>
	</div>
</div>

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

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

	function loadTabelOrderService() {
		tb = $(".tabel-order-service").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('order_service/get_data') }}',
	        columns: [
	            {data: 'id', name: 'id', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'nama_lokasi', name: 'nama_lokasi'},
	            {data: 'tanggal_nota', name: 'tanggal_nota'},
	            {data: 'nomor_nota', name: 'no_nota'},
	            {data: 'nama_penyedia', name: 'nama_penyedia'},
	            {data: 'tagihan', name: 'tagihan'},
	            {data: 'sisa_tagihan', name: 'sisa_tagihan'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        createdRow: function(row, data, index) {
	        	$( row ).attr("data-id", data.id);
                $('td', row).eq(5).html(accounting.formatMoney(data.tagihan)).attr('align','right'); // 6 is index of column
                $('td', row).eq(6).html(accounting.formatMoney(data.sisa_tagihan)).attr('align','right'); // 6 is index of column
                $('td', row).eq(8).attr('nowrap','');
                    
            },
		});
	}

	function btnEditOrderService(this_) {
		var id = this_.parents('tr').data('id');
	}

	function btnPrintOrderService(this_) {
		var id = this_.parents('tr').data('id');
		var href = this_.data("href");
		$("#form-cetak-orderservice").attr("action", href);
		$("#form-cetak-orderservice").find("input[name=tanggal_cetak]").val('{{date("d-m-Y")}}');

		var row_data = tb.row(this_.parents("tr")).data();
		console.log(row_data);
		$(".text-no-orderservice").html(row_data.no_nota+row_data.sufix_no_nota);
		$(".text-tanggal-orderservice").html(row_data.tanggal);
		$(".text-supplier-orderservice").html(row_data.nama_penyedia);
		$(".text-tagihan-orderservice").html(accounting.formatMoney(row_data.tagihan));

		showModal($("#cetak-orderservice"));
	}
	
	function btnDeleteOrderService(this_) {
		var id = this_.parents('tr').data('id');
		swal({
			title: 'Anda yakin akan menghapus data ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('order_service')}}/"+id,
					type: 'post',
					data: {'_method':'DELETE'},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						if(respon.status==1){
							tb.ajax.reload();
						}else{
							console.log("Kesalahan Operasi...");
						}
					}
				})
		 	}
		})
	}
</script>
@endsection