@extends('layouts.app')

@section('content')
<div class="container">
	<section class="content">
	    <div class="row">
	    	<div class="col-md-12">
	        	<div class="box box-primary">
	            	<div class="box-header">
	                	<h3 class="box-title">Excel Download From <i>{{ $startDate }}</i> To <i>{{ $endDate }}</i></h3>
	            	</div>
	            	<div class="box-body">
	                    <div class="table-responsive"> 
	                        <table id="example" class="table table-bordered table-striped">
	                            <thead>
	                                <tr>
			                            <th>TID</th>
			                            <th>Subject</th>
			                            <th>Assigned</th>
			                            <th>Ticket Type</th>
			                            <th>Ticket Status</th>
			                            <th>Cus. Name</th>
			                            <th>Phone No</th>
			                            <th>Cus. Address</th>
			                            <th>Product Detail</th>
			                            <th>Product Price</th>
			                            <th>Total Price</th>
			                            <th>Online Payment</th>
			                            <th>Client & Dis</th>
			                            <th>DB Assigned</th>
			                            <th>Remarks</th>
			                            <th>CreatedAt</th>
			                            <th>UpdatedAt</th>
			                            <th>CreatedBy</th>
			                            <th>UpdatedBy</th>
		                            </tr>
	                            </thead>
	                            <tbody>
	                            <?php
	                                $i = 0;
	                            ?>
	                            @foreach($tickets as $ticket)
	                            	
	                                <tr>
			                            <td>{{ $ticket->id }}</td>
			                            <td>{{ $ticket->subject }}</td>
			                            @if(isset($ticket->assigned->name))
	                                        <td>{{ $ticket->assigned->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
			                            @if(isset($ticket->ticketType->name))
	                                        <td>{{ $ticket->ticketType->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
			                            @if(isset($ticket->ticketStatus->name))
	                                        <td>{{ $ticket->ticketStatus->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
			                            <td>{{ $ticket->customer_name }}</td>
			                            <td>{{ $ticket->phone_number }}</td>
			                            <td>{{ $ticket->customer_address }}</td>

			                            <?php
                                            $productDetail = str_replace( ['[', ']', '{', '}', '"'], "", $ticket->product_detail );
                                        ?>

			                            <td>{{ $productDetail }}</td>
			                            <td>{{ $ticket->product_price }}</td>
			                            <td>{{ $ticket->total_price }}</td>
			                            <td>{{ $ticket->online_payment }}</td>
			                            <td>{{ $ticket->client_discount }}</td>
			                            @if(isset($ticket->dbAssigned->name))
	                                        <td>{{ $ticket->dbAssigned->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
	                                    <td>{{ $ticket->remarks }}</td>
	                                    <td>{{ $ticket->created_at }}</td>
	                                    <td>{{ $ticket->updated_at }}</td>
			                            @if(isset($ticket->createdBy->name))
	                                        <td>{{ $ticket->createdBy->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
			                            @if(isset($ticket->updatedBy->name))
	                                        <td>{{ $ticket->updatedBy->name }}</td>
	                                    @else
	                                        <td></td>
	                                    @endif
	                                </tr>
	                            @endforeach
	                            </tbody>
	                        </table>
	                    </div>
	            	</div>
	      		</div>
	    	</div>
	  	</div>
	</section>
</div>
@endsection

@section('style')
    <link rel="stylesheet" href="{{ asset('assets/css/dataTables.bootstrap.min.css') }}">
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.0/css/buttons.dataTables.min.css">
@endsection

@section('script')
    <script src="{{ asset('assets/js/jquery.dataTables.min.js') }}"></script>
    <script src="{{ asset('assets/js/dataTables.bootstrap.min.js') }}"></script>


  	<script src="https://cdn.datatables.net/buttons/1.6.0/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.6.0/js/buttons.print.min.js"></script>

    <script type="text/javascript">
		$(document).ready(function() {
		    $('#example').DataTable( {
		        dom: 'Bfrtip',
		        buttons: [
		            'excel'
		        ]
		    } );
		} );
	</script>
@endsection