<style>
    <?php include(public_path().'/css/style.css');?>
    <?php include(public_path().'/css/font-awesome.css');?>
</style>
<style>
body {
    background-color: white !important;
}
</style>
@php
    $invoice_date = "";
    $invoice_number ="";
    $qr_string ="";
    $invoice_date = $invoice->invoice_date;
    if($invoice_date)
    {
        $invoice_month = date('m',strtotime($invoice_date));
        $invoice_year = date('Y',strtotime($invoice_date));
        $invoice_no = $invoice->invoice_no;
        $org_code = $invoice->organisation->short_code;
        if($invoice_month<4)
            $invoice_year--;

        $nextyear = $invoice_year+1;

        $invoice_number = $org_code.'/'.$invoice_no.'/'.$invoice_year.'-'.$nextyear;
    }

    if($invoice->status==1)
        $invoice_status = 'Paid';
    else if($invoice->status==0)
        $invoice_status = 'Pending';
    else
        $invoice_status = 'Cancelled';

    //get adults and child count from tickets
    foreach($invoice->tickets as $ticket)
    {
        $adultCount = $ticket->noof_adult;
        $childCount = $ticket->noof_child;
    }

    $totalCount = $adultCount+$childCount;

    if($invoice_date)
    {
        $secretkey='KSSTM'.$invoice_number.$invoice_date;
        $secretmd5 = md5($secretkey);
    
        $qr_string=$invoice_number.'~'.$invoice_date.'~'.'Adult:'.$adultCount.'~'.'Child:'.$childCount.'~'.$invoice_status.'~'.'Secret:'.$secretmd5;
    }
    
@endphp
<div class="table-responsive">
    <table class="table table-clear">
        <tr>
            <td colspan="2"><img class="logo-abbr mr-2" width="80" src="{{public_path('images/logo_ksstm.png')}}" alt=""></td><td colspan="2" align="right"><img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(80)->generate($qr_string)) !!} "></td>
        </tr>
        <tr>
            <td colspan="4"><div class=""> Invoice #: <strong>{{$invoice_number}}</strong><span class="float-right">
                                    <strong>Status:</strong> {{$invoice_status}}</span> </div>
            </td>
        </tr>
        <tr><td>Show Date:</td><td><strong>{{date('d-m-Y', strtotime($invoice->show_date))}}</strong></td><td>Visitor Name:</td><td><strong>{{$invoice->publicuser->name}}</strong></td></tr>
        <tr><td>Centre:</td><td colspan="3"><strong>{{$invoice->organisation->organisation_name}},&nbsp;{{$invoice->organisation->city}}</strong></td></tr>
        <tr><td>Adults#:</td><td><strong>{{$adultCount}}</strong></td><td>Child#:</td><td><strong>{{$childCount}}</strong></td></tr>
        <tr><td colspan="4" align="center"><span> <strong class="d-block" style="border:orange; border-width:2px; border-style:solid; text-align: center;"><p style="margin:5px !important;">Total Permit:&nbsp;{{$totalCount}}</p></strong>
                                                    </span></td></tr>
        <tr><td colspan="4"><small class="text-muted">*Ticket subjected to verification at Counters</small></td></tr>
    </table>
    <table class="table table-striped">
        <thead>
            <tr>
                <th class="center">#</th>
                <th>Ticket#</th>
                <th>Facility</th>
                <th class="right">Show Time</th>
                <th class="right">Amount</th>
            </tr>
        </thead>
        <tbody>
            @php $j=0; @endphp
            @foreach($invoice->tickets as $ticket)
            @php $j++; @endphp
            <tr>
                <td class="center">{{$j}}</td>
                <td class="left strong">{{$org_code}}/{{$ticket->facility->short_code}}/{{$ticket->ticket_no}}/{{$invoice_year}}-{{$nextyear}}</td>
                <td class="left">{{$ticket->facility->facility_name}}</td>
                <td class="right">{{$ticket->showtime->from_time}}&nbsp;-&nbsp;{{$ticket->showtime->to_time}}
                    <p>
                        @php
                            if($ticket->facility->fixedseatflag)
                            {
                                echo "Seat(s) : ";
                                for($i=1; $i<=$totalrows; $i++)
                                {
                                    $printseatstring='';
                                    $firstseat='';
                                    $prevrowname='';
                                    $colcount=0;
                                    @endphp
                                    @foreach($seat_name_row[$i] as $rowseatname)
                                        @php
                                        $colcount++;
                                            if(in_array($rowseatname, $seatname_ticket))
                                            {
                                                if(!$firstseat)
                                                {
                                                    $firstseat = $rowseatname;
                                                    $printseatstring = $firstseat;
                                                }


                                                 $prevrowname = $rowseatname;

                                                 if($colcount==sizeof($seat_name_row[$i]) && $firstseat!=$rowseatname)
                                                 {
                                                    $printseatstring .= '-'.$rowseatname;
                                                 }
                                            }
                                            else
                                            {
                                                if($prevrowname)
                                                    $printseatstring .= '-'.$prevrowname;

                                                $prevrowname = '';
                                                $firstseat ='';
                                                if($printseatstring)
                                                    echo $printseatstring.", ";

                                                $printseatstring = '';
                                            }

                                        @endphp
                                    @endforeach
                                    @php
                                    if($printseatstring)
                                        echo $printseatstring."<br>";
                                }
                            }
                        @endphp                                
                    </p>
                </td>
                <td class="right">Rs.&nbsp;{{$ticket->amount}}</td>
            </tr>
            @endforeach
            
        </tbody>
    </table>
    <table class="table table-clear">
        <tbody>
            
            <tr>
                <td class="left"><strong>Total</strong></td>
                <td class="right"><strong>Rs.&nbsp;{{$invoice->amount}}/-</strong><br>
                    </td>
            </tr>
        </tbody>
    </table>

</div>

		