{{-- Extends layout --}}
@extends('layout.default')
@section('content')
    <div class="container-fluid">
        <div class="page-titles">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="javascript:void(0)">Reports</a></li>
                <li class="breadcrumb-item active"><a href="javascript:void(0)">Financial Report</a></li>
            </ol>
        </div>
        <div class="row">
            <div class="col-12">
                <div class="card card-primary">
                    <div class="card-body"> 
                        <div class="form-row">
                            <div class="form-group col-6">
                                @php
                                    $date_from_crt = date("d-M-Y", strtotime($date_from));
                                    $date_to_crt = date("d-M-Y", strtotime($date_to));
                                @endphp
                                <u><b>FINANCIAL STATEMENT ({{$date_from_crt}} to {{$date_to_crt}})</b></u>
                            </div>
                            <div class="form-group col-6">
                                <span style="text-align: right; padding-right:20px; "> 
                                    <form class="form-horizontal" action="{{URL::to('/financial_report_pdf')}}" method="post" autocomplete="off">
                                        <!-- CSRF Token -->
                                        <input type="hidden" name="_token" value="{{csrf_token()}}">  
                                        <button type="submit" class="btn btn-xs btn-info pull-right" id="reg_btn" >Generate PDF</button>
                                        <input type="hidden" name="date_from" id="date_from" value="{{$date_from}}">
                                        <input type="hidden" name="date_to" id="date_to" value="{{$date_to}}">
                                        <input type="hidden" name="user_id" id="user_id" value="{{$user_id}}">
                                        <input type="hidden" name="organisation_id" id="organisation_id" value="{{$organisation_id}}">
                                    </form>
                                </span>
                            </div>
                        </div>                
                        <div class="table-responsive"> 
                            @foreach($facilities as $facility)
                                <table class="table table-sm table-responsive-lg mb-0" style="font-size:90%;">
                                    <div class="card-header">
                                        <span style="color: blue;"><b>{{strtoupper($facility->facility_name)}}</b></span>
                                    </div>
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Date</th>
                                            <th>Show Time</th>
                                            <th># of Adults</th>
                                            <th># of Children</th>
                                            <th>Amount</th>
                                        </tr>
                                    </thead>
                                    @php                                                        
                                        $facility_id = $facility->id;
                                        $total_adults =0;
                                        $total_children = 0;
                                        $totalamount=0;
                                        //dd($ticket_date_arr);
                                    @endphp
                                    <!-- regular show -->
                                        @if(isset($flg[$facility_id]))
                                            @if($flg[$facility_id]==1)
                                                <tr>
                                                    <td colspan="6">
                                                        <b style="color: green;">REGULAR SHOW</b>
                                                    </td>
                                                </tr>
                                                @php
                                                    $n = 0;
                                                @endphp 
                                                                                           
                                                    @if(isset($ticket_array[$facility_id]))
                                                        @foreach($ticket_array[$facility_id] as $tickets)
                                                            @if($tickets['noofadults'])
                                                                @php
                                                                    $n++;
                                                                    if($total_adults)
                                                                    {
                                                                        $total_adults = $total_adults+$tickets['noofadults'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $total_adults = $tickets['noofadults'];
                                                                    }
                                                                    if($total_children)
                                                                    {
                                                                        $total_children = $total_children+$tickets['noofchildren'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $total_children = $tickets['noofchildren'];
                                                                    }
                                                                    if($totalamount)
                                                                    {
                                                                        $totalamount = $totalamount+$tickets['amount'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $totalamount = $tickets['amount'];
                                                                    }
                                                                @endphp
                                                                <tr>
                                                                    <td>{{$n}}</td>
                                                                    <td>{{date("d-M-Y", strtotime($tickets['date']))}}</td>
                                                                    <td>{{$tickets['showtime']}}</td>
                                                                    <td style="text-align: center;">{{$tickets['noofadults']}}</td>
                                                                    <td style="text-align: center;">{{$tickets['noofchildren']}}</td>
                                                                    <td style="text-align: right;"><i class='fa fa-rupee'></i>&nbsp;{{$tickets['amount']}}</td>
                                                                </tr>
                                                            @endif             
                                                        @endforeach
                                                    @endif                                                      
                                                
                                            @endif
                                        @endif
                                    <!-- end -->

                                    <!--special shows-->
                                    
                                        @if(isset($splflg[$facility_id]))
                                            @if($splflg[$facility_id]==1)
                                                <tr>
                                                    <td colspan="6">
                                                        <b style="color: green;">SPECIAL SHOW</b>
                                                    </td>
                                                </tr>
                                                @php
                                                    $n = 0;
                                                @endphp  
                                                                                              
                                                    @if(isset($spl_ticket_array[$facility_id]))                                               
                                                        @foreach($spl_ticket_array[$facility_id] as $spl_tickets)
                                                            @if($spl_tickets['noofadults'])
                                                                @php
                                                                    $n++;
                                                                    if($total_adults)
                                                                    {
                                                                        $total_adults = $total_adults+$spl_tickets['noofadults'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $total_adults = $spl_tickets['noofadults'];
                                                                    }
                                                                    if($total_children)
                                                                    {
                                                                        $total_children = $total_children+$spl_tickets['noofchildren'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $total_children = $spl_tickets['noofchildren'];
                                                                    }
                                                                    if($totalamount)
                                                                    {
                                                                        $totalamount = $totalamount+$spl_tickets['amount'];
                                                                    }
                                                                    else
                                                                    {
                                                                        $totalamount = $spl_tickets['amount'];
                                                                    }
                                                                @endphp
                                                                <tr>
                                                                    <td>{{$n}}</td>
                                                                    <td>{{date("d-M-Y", strtotime($spl_tickets['date']))}}</td>
                                                                    <td>{{$spl_tickets['showtime']}}</td>
                                                                    <td style="text-align: center;">{{$spl_tickets['noofadults']}}</td>
                                                                    <td style="text-align: center;">{{$spl_tickets['noofchildren']}}</td>
                                                                    <td style="text-align: right;"><i class='fa fa-rupee'></i>&nbsp;{{$spl_tickets['amount']}}</td>
                                                                </tr>
                                                            @endif             
                                                        @endforeach
                                                    @endif                                                     
                                                
                                            @endif
                                        @endif
                                    <!-- end -->

                                    <tr>
                                        <td><b>Total</b></td>
                                        <td></td>
                                        <td></td>
                                        <td style="text-align: center;"><b>{{$total_adults}}</b></td>
                                        <td style="text-align: center;"><b>{{$total_children}}</b></td>
                                        <td style="text-align: right;"><i class='fa fa-rupee'></i>&nbsp;<b>{{$totalamount}}</b></td>
                                    </tr> 
                                </table>
                            @endforeach
                        </div>                                       
                    </div>
                </div>
            </div>
        </div>
    </div>
    
@stop