<?php $__env->startSection('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)">Facility Detailed Report</a></li>
        </ol>
    </div>
    <div class="row">
        <div class="col-12">
            <div class="card card-primary">
                <div class="card-body"> 
                    <div class="default-tab">
                        <div class="tab-content">
                            <div class="form-row">
                                <div class="form-group col-3">
                                    <?php
                                        $date_from_crt = date("d-M-Y", strtotime($date_from));
                                    ?>
                                    <b>Date From : </b><?php echo e($date_from_crt); ?>

                                </div>
                                <div class="form-group col-3">
                                    <?php
                                        $date_to_crt = date("d-M-Y", strtotime($date_to));
                                    ?>
                                    <b>Date To : </b><?php echo e($date_to_crt); ?>

                                </div>
                                <?php
                                    $date_val = " From ".$date_from_crt." To ".$date_to_crt;
                                ?>
                            </div>                
                            <div class="tab" id="listdata" style="padding-top: 30px;">       
                                <div class="table-responsive"> 
                                    <table class="display" style="width:100%" id="detailed_report">
                                        <thead class="thead-info">
                                            <tr>
                                                <th>Sl No</th>
                                                <th>Date</th>
                                                <th>Facility Name</th>
                                                <th>Ticket Number</th>
                                                <th># of Adults</th>
                                                <th># of Children</th>
                                                <th>Amount</th>
                                                <th>Mode of Payment</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                $n = 0;
                                                $invoice_date= "";
                                                $invoice_month="";
                                                $invoice_year = "";
                                                $invoice_no = "";
                                                $org_code ="";
                                                $nextyear ="";
                                                $invoice_number ="";
                                                $ticket_number ="";
                                                $payment_method ="";
                                            ?>
                                            <?php $__currentLoopData = $ticket_date_arr; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dates): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php $__currentLoopData = $ticket_query[$dates]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tickets): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?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;

                                                        $ticket_number = $org_code.'/'.$tickets->facility->short_code.'/'.$tickets->ticket_no.'/'.$invoice_year.'-'.$nextyear;
                                                        $ticket_no = $ticket_number;
                                                        $adult_count = $tickets->noof_adult;
                                                        $child_count = $tickets->noof_child;
                                                        $totalamount = $tickets->amount;
                                                        if($tickets->invoice->payment_method)
                                                        {
                                                            $payment_method = $tickets->invoice->paymentmethod->method;
                                                        }
                                                        if($ticket_no!="")
                                                        {
                                                            $n++;
                                                            ?>
                                                            <tr>
                                                                <td><?php echo e($n); ?></td>
                                                                <td><?php echo e(date("d-M-Y", strtotime($dates))); ?></td>
                                                                <td><?php echo e($tickets->facility->facility_name); ?></td>
                                                                <td><?php echo e($ticket_no); ?></td>
                                                                <td style="text-align: center;"><?php echo e($tickets->noof_adult); ?></td>
                                                                <td style="text-align: center;"><?php echo e($tickets->noof_child); ?></td>
                                                                <td style="text-align: right;"><?php echo e($tickets->amount); ?></td>
                                                                <td style="text-align: center;"><?php echo e($payment_method); ?></td>
                                                            </tr>
                                                            <?php
                                                        }
                                                    ?>                
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </tbody>
                                        <tfoot class="tfoot-info">
                                            <tr>
                                                <th>Total</th>
                                                <th>&nbsp;</th>
                                                <th>&nbsp;</th>
                                                <th>&nbsp;</th>
                                                <th>&nbsp;</th>
                                                <th>&nbsp;</th>
                                                <th align="right">&nbsp;</th>
                                                <th>&nbsp;</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div> 
                            </div>
                        </div>     
                    </div>                                       
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () 
    {
        var table = $('#detailed_report').DataTable({
                pageLength : 100,
                columnDefs: 
                [
                    {
                        className: "text-center", targets: [3, 4, 5]
                    },
                    {
                        className: "text-right", targets: [6]
                    },
                ],
                dom: 'lfBrtip',
                buttons: [
                        { extend: 'excelHtml5', title: '<?php echo $org_name; ?>' + '\n' + '<?php echo $date_val; ?>', footer: true, filename: 'Detailed report' },
                        { extend: 'pdfHtml5', title: '<?php echo $org_name; ?>' + '\n' + '<?php echo $date_val; ?>', footer: true, filename: 'Detailed report' }
                ],
                footerCallback: function (row, data, start, end, display) {
                    var api = this.api();
         
                    // Remove the formatting to get integer data for summation
                    var intVal = function (i) {
                        return typeof i === 'string' ? i.replace(/[\$,]/g, '') * 1 : typeof i === 'number' ? i : 0;
                    };
         
                    // Total over all pages
                    total = api
                        .column(6)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
         
                    // Total over this page
                    pageTotal = api
                        .column(6, { page: 'current' })
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
         
                    // Update footer
                    //alert(total);
                    //$(api.column(7).footer()).html('' + pageTotal + ' ( ' + total + ' total)');
                    $(api.column(6).footer()).html(total);
                },
                createdRow: function ( row, data, index ) {
                   $(row).addClass('selected')
                } 
            });
              
            table.on('click', 'tbody tr', function() {
            var $row = table.row(this).nodes().to$();
            var hasClass = $row.hasClass('selected');
            if (hasClass) {
                $row.removeClass('selected')
            } else {
                $row.addClass('selected')
            }
            })
            
            table.rows().every(function() {
            this.nodes().to$().removeClass('selected')
            });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.default', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/ksstmorg/resources/views/Reports/detailed_report_list.blade.php ENDPATH**/ ?>