{{-- Extends layout --}}
@extends('layout.default')
{{-- Content --}}
@section('content')


<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            @if($ticket_count>0)
                @php
                    $invoice_date = $tickets->invoice->invoice_date;
                    $invoice_month = date('m',strtotime($invoice_date));
                    $invoice_year = date('Y',strtotime($invoice_date));
                    $invoice_no = $tickets->invoice->invoice_no;
                    $org_code = $tickets->invoice->organisation->short_code;
                    if($invoice_month<4)
                        $invoice_year--;

                    $nextyear = $invoice_year+1;

                    $invoice_number = $org_code.'/'.$invoice_no.'/'.$invoice_year.'-'.$nextyear;

                    if($tickets->status==1)
                        $invoice_status = 'Paid';
                    else if($tickets->status==0)
                        $invoice_status = 'Pending';
                    else
                        $invoice_status = 'Cancelled';

                    //get adults and child count from tickets
                    
                    $adultCount = $tickets->noof_adult;
                    $childCount = $tickets->noof_child;
                    $totalCount = $adultCount+$childCount;
                    $payment_type = $tickets->invoice->payment_type;
                    $payment_method = $tickets->invoice->payment_method;
                @endphp
                <div class="card ">
                    <div class="card-header"> <div> <strong>Invoice Date : </strong><br><small>{{date('d-m-Y', strtotime($invoice_date))}}</small></div> <span class="float-right">
                            <strong>Invoice Status :</strong> {{$invoice_status}}</span> </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-xl-6 col-sm-6 mb-8">
                                <div class="col-sm-12 row"><div class="col-sm-4"> Invoice #:&nbsp;</div><div class="col-sm-8"><strong>{{$invoice_number}}</strong> </div></div>
                                <div class="col-sm-12 row"><div class="col-sm-4"> Show Date:&nbsp;</div><div class="col-sm-8"><strong>{{date('d-m-Y', strtotime($tickets->show_date))}}</strong> </div></div>
                                <div class="col-sm-12 row">
                                    <div class="col-sm-4"> Visitor:&nbsp;</div>
                                    <div class="col-sm-8">
                                        <strong>{{$tickets->invoice->visitor_name}} 
                                            @if($tickets->invoice->visitor_phone_number)
                                            ({{$tickets->invoice->visitor_phone_number}})
                                            @endif
                                        </strong> 
                                    </div>
                                </div>
                                <div class="col-sm-12 row"><div class="col-sm-4"> Centre:&nbsp;</div><div class="col-sm-8"><strong>{{$tickets->invoice->organisation->organisation_name}},&nbsp;{{$tickets->invoice->organisation->city}}</strong> </div></div>
                            </div>
                            
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th class="center">#</th>
                                        <th>Ticket #</th>
                                        <th>Adult #</th>
                                        <th>Child #</th>
                                        <th>Facility</th>
                                        <th class="right">Show Time</th>
                                        <th class="right">Ticket Amount</th>
                                        <th class="right">Refund Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @php 
                                        $i=0; 
                                        $totalrefund = 0;
                                    @endphp
                                    @if(isset($tickets))
                                        @php 
                                            $i++; 
                                            $org_code = $tickets->facility->organisation->short_code;
                                            $facility_short_code = $tickets->facility->short_code;
                                            $ticket_no = $tickets->ticket_no;
                                            $invoice_date = $tickets->invoice->invoice_date;
                                            $invoice_month = date('m',strtotime($invoice_date));
                                            $invoice_year = date('Y',strtotime($invoice_date));
                                            if($invoice_month<4)
                                                $invoice_year--;
                                            $nextyear = $invoice_year+1;
                                        @endphp
                                        <tr>
                                            <td class="center">{{$i}}</td>
                                            <td class="center">
                                                @if(isset($tickets->ticket_no))
                                                    <strong>{{$org_code}}/{{$facility_short_code}}/{{$ticket_no}}/{{$invoice_year}}-{{$nextyear}}</strong>
                                                @endif
                                            </td>
                                            <td class="left strong">{{$tickets->noof_adult}}</td>
                                            <td class="left strong">{{$tickets->noof_child}}</td>
                                            <td class="left">{{$tickets->facility->facility_name}}</td>
                                            <td class="right">{{date("H:i A", strtotime($tickets->showtime->from_time))}}&nbsp;-&nbsp;{{date("H:i A", strtotime($tickets->showtime->to_time))}}</td>
                                            <td class="right"><i class='fa fa-rupee'></i>&nbsp;{{$tickets->amount}}</td>
                                            <td class="right"><i class='fa fa-rupee'></i>&nbsp;
                                                @if(isset($refundticket[$tickets->id]))
                                                    {{$refundticket[$tickets->id]}}
                                                @endif
                                            </td>
                                        </tr>
                                        @php 
                                            $totalrefund += $refundticket[$tickets->id];
                                        @endphp
                                    @endif
                                    <tfoot>
                                        <tr>
                                            <td colspan="7" align="right"><strong><h4>Total Refund Amount:&nbsp;&nbsp;&nbsp;<i class='fa fa-rupee'></i>&nbsp;{{$totalrefund}}</h4></strong></td>
                                        </tr>
                                        <tr>
                                            <td colspan="7">
                                                @php $mess=""; @endphp
                                                @if($payment_type==1)
                                                    @php
                                                        $mess = "The payment for this ticket is Online.";
                                                    @endphp
                                                @elseif(($payment_method==2) && ($payment_type==2))
                                                    @php
                                                        $mess = "The payment for this ticket is via CARD.";
                                                    @endphp
                                                @elseif(($payment_method==3) && ($payment_type==2))
                                                    @php
                                                        $mess = "The payment for this ticket is via UPI.";
                                                    @endphp
                                                @else
                                                    @if($refundticket[$tickets->id]>0)
                                                        <!-- check whether cancel request already send or not -->
                                                        @if($ticket_cancel_list_count==0)
                                                        <!-- end-->
                                                            <form action="{!! url('/ticket_cancellation_approval'); !!}" method="post">
                                                                {{ csrf_field() }}
                                                                <button class="btn btn-success pull-right" type="submit" value="Approve" id="btnValue" name="btnValue">Cancel & Approve Ticket</button>
                                                                <input type="hidden" name="invoice_id" id="invoice_id" value="{{$tickets->invoice->id}}">
                                                                <input type="hidden" name="ticket_id" id="ticket_id" value="{{$tickets->id}}">
                                                            </form>
                                                        @endif
                                                    @endif
                                                @endif
                                                <span class="pull-right" style="color: red;"><b>{{$mess}}</b></span>
                                            </td>
                                        </tr>
                                    </tfoot>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            @else
                <div class="card card-body card-header">
                    <div> <strong> No Ticket Available !!!</strong></div>
                </div>
            @endif
        </div>
    </div>
</div>

@endsection			