<?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)">Refund 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-12">
                                <?php
                                    $date_from_crt = date("d-M-Y", strtotime($date_from));
                                    $date_to_crt = date("d-M-Y", strtotime($date_to));
                                ?>
                                <?php
                                    $date_val = " From ".$date_from_crt." To ".$date_to_crt;
                                ?>
                                <?php if(isset($organisations)): ?>
                                    <?php
                                        $org_name = $organisations->organisation_name."(".$organisations->city.")";
                                    ?>
                                <?php endif; ?>
                                <u><b>REFUND REPORT FROM (<?php echo e($date_from_crt); ?> to <?php echo e($date_to_crt); ?>)</b>
                                    <?php if(isset($organisations)): ?>
                                        at <?php echo e($organisations->organisation_name); ?>(<?php echo e($organisations->city); ?>)
                                    <?php endif; ?>
                                </u>
                            </div>
                        </div>         
                        <div class="tab" id="listdata" style="padding-top: 30px;">          
                            <div class="table-responsive"> 
                                <table class="table table-sm table-responsive-lg mb-0" style="font-size:90%;" id="refund_list">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Refund Initialization Date</th>
                                            <th>Show Date</th>
                                            <th>Invoice #</th>
                                            <th>Ticket #</th>
                                            <th># of Adults</th>
                                            <th># of Children</th>
                                            <th>Ticket Amount</th>
                                            <th>Refund Amount</th>
                                            <th>Refund Amount Rejected</th>
                                            <th>Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php        
                                            $refund_initialization_date = "";                                                
                                            $invoice_date= "";
                                            $invoice_month="";
                                            $invoice_year = "";
                                            $invoice_no = "";
                                            $org_code ="";
                                            $nextyear ="";
                                            $invoice_number ="";
                                            $ticket_number ="";
                                            $show_date ="";
                                            $adult_count ="";
                                            $child_count ="";
                                            $refund_amount ="";
                                            $ticket_amount ="";
                                            $refund_status ="";
                                            $status_name ="";
                                            $n = 0;
                                        ?>
                                        <?php $__currentLoopData = $refunds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $refund): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>   
                                            <?php
                                                $n++;  
                                                $refund_id = $refund->id;
                                                $refund_initialization_date = $refund->created_at;
                                                if($refund_initialization_date)
                                                {
                                                    $refund_initialization_date = date("d-M-Y", strtotime($refund_initialization_date));
                                                }
                                                $invoice_date = $refund->invoice->invoice_date;
                                                $invoice_month = date('m',strtotime($invoice_date));
                                                $invoice_year = date('Y',strtotime($invoice_date));
                                                $invoice_no = $refund->invoice->invoice_no;
                                                $org_code = $refund->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.'/'.$refund->ticket->facility->short_code.'/'.$refund->ticket->ticket_no.'/'.$invoice_year.'-'.$nextyear;

                                                $show_date = $refund->show_date;
                                                if($show_date)
                                                {
                                                    $show_date = date("d-M-Y", strtotime($show_date));
                                                }
                                                $adult_count = $refund->adult_count;
                                                $child_count = $refund->child_count;
                                                $refund_amount = $refund->refund_amount;
                                                $ticket_amount = $refund->ticket->amount;
                                                $refund_status = $refund->refund_status;
                                                if($refund_status==0)
                                                {
                                                    $status_name = "Refund Initiated";
                                                }
                                                if($refund_status==1)
                                                {
                                                    $status_name = "Refund Processed";
                                                }
                                                if($refund_status==2)
                                                {
                                                    $status_name = "Refund Rejected";
                                                }
                                            ?>                                                
                                            <tr>
                                                <td><?php echo e($n); ?></td>
                                                <td><?php echo e($refund_initialization_date); ?></td>
                                                <td><?php echo e($show_date); ?></td>
                                                <td><?php echo e($invoice_number); ?></td>
                                                <td><?php echo e($ticket_number); ?></td>
                                                <td style="text-align: center;"><?php echo e($adult_count); ?></td>
                                                <td style="text-align: center;"><?php echo e($child_count); ?></td>
                                                <td style="text-align: center;"><?php echo e($ticket_amount); ?></td>
                                                <td style="text-align: center;">
                                                    <?php if($refund_status==1): ?>
                                                        <?php echo e($refund_amount); ?>

                                                    <?php endif; ?>
                                                </td>
                                                <td style="text-align: center;">
                                                    <?php if($refund_status==2): ?>
                                                        <?php echo e($refund_amount); ?>

                                                    <?php endif; ?>
                                                </td>
                                                <td><?php echo e($status_name); ?></td>
                                            </tr>     
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                    <tfoot class="tfoot-info">
                                        <tr>
                                            <th>&nbsp;</th>
                                            <th>Filters</th>
                                            <th>
                                                <?php
                                                    $date_from_crt = date("d-M-Y", strtotime($date_from));
                                                ?>
                                                <b>From : </b><?php echo e($date_from_crt); ?>

                                            </th>
                                            <th>
                                                <?php
                                                    $date_to_crt = date("d-M-Y", strtotime($date_to));
                                                ?>
                                                <b>To : </b><?php echo e($date_to_crt); ?>

                                            </th>
                                            <th>&nbsp;</th>
                                            <th>&nbsp;</th>
                                            <th>&nbsp;</th>
                                            <th>Total</th>
                                            <th>Refund Amount</th>
                                            <th>&nbsp;</th>
                                            <th>&nbsp;</th>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>   
                        </div>                                    
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () 
        {
            var table = $('#refund_list').DataTable({
                    columnDefs: 
                    [
                        {
                            className: "text-center", targets: [3, 4]
                        },
                        {
                            className: "text-center", targets: [5]
                        },
                    ],
                    dom: 'lfBrtip',
                    buttons: [
                        { extend: 'excelHtml5',title: '<?php echo $org_name; ?>' + '\n' + '<?php echo $date_val; ?>', footer: true, filename: 'Refund Report',orientation : 'landscape' },
                        { extend: 'pdfHtml5',title: '<?php echo $org_name; ?>' + '\n' + '<?php echo $date_val; ?>', footer: true, filename: 'Refund Report',orientation : 'landscape' }
                    ],
                    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(7)
                            .data()
                            .reduce(function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0);
             
                        // Total over this page
                        pageTotal = api
                            .column(7, { page: 'current' })
                            .data()
                            .reduce(function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0);
             
                        // Update footer
                        $(api.column(7).footer()).html("Total : "+total);

                        // Total refund processed over all pages
                        total_ref_processed = api
                            .column(8)
                            .data()
                            .reduce(function (a, b) {
                                return intVal(a) + intVal(b);
                            }, 0);
                          
                        // Update footer
                        $(api.column(8).footer()).html("Refund Amount : "+total_ref_processed);

                    
                        
                    },
                    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/ksstmprod/resources/views/Reports/refund_report_list.blade.php ENDPATH**/ ?>