
<?php $__env->startSection('content'); ?>
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
    <link href="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.bootstrap4.css" rel="stylesheet"
          type="text/css" />
    <link href="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/datatables.mark.css" rel="stylesheet"
          type="text/css" />
    <link href="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/buttons.bootstrap4.css" rel="stylesheet"
          type="text/css" />
    <link href="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/responsive.bootstrap4.css" rel="stylesheet"
          type="text/css" />
    <link href="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/select.bootstrap4.css" rel="stylesheet"
          type="text/css" />
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>

    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-lg-12 ">
                    <div class="card radius-10">
                        <div class="card-header">
                            <h4>View Offers Report</h4>
                        </div>
                        <div class="card-body">

                            <form method="get" action="<?php echo e(url('/admin/view-offer-report-s')); ?>"><?php echo e(csrf_field()); ?>

                                <div class="row" style="margin-bottom: 15px;">
                                    <div class="col-lg-3">
                                        <label class="form-label" for="from_date">From</label>
                                        <input type="date" name="from_date" id="from_date"  class="form-control">
                                    </div>
                                    <div class="col-lg-3">
                                        <label class="form-label" for="to_date">To</label>
                                        <input type="date" name="to_date" id="to_date" class="form-control">
                                    </div>
                                    <div class="col-lg-3">

                                        <button type="submit" class="btn btn-success" style="margin-top: 30px;">Filter</button>
                                    </div>

                                </div>



































                            </form>
                            <?php
                            $total_clck = 0;
                            $total_lead = 0;
                            $total_earning = 0;
                            $total_cvr = 0;
                            $total_u_click = 0;
                            $total_ecpm = 0;
                            $total = 0;
                            ?>

                            <div class="row" style="overflow-x: auto;">
                                <h6>Summary</h6>

                                <table class="table table-bordered table-striped dt-responsive nowrap"
                                       style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                                    <thead class="thead thead-light" >
                                    <tr>
                                        <th>Click</th>
                                        <th>Leads</th>
                                        <th>Earning</th>
                                        <th>Unique Click</th>
                                        <th>CR</th>
                                        <th>CVR</th>
                                        <th>ECPM</th>

                                    </tr>
                                    </thead>
                                    <tbody class="text-dark" >
                                         <?php $__currentLoopData = $offer; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=> $off): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php
                                                $total_clck += count($off);
                                                $total_lead += count($off->where('status', 'Approved'));
                                                
                                                
                                                    foreach($off->where('status', 'Approved') as $offs){
                                                         $total_earning += $offs->payout;
                                                    }
                                                   
                                                    
                                                    $total_cvr += (int)count($off->where('status', 'Approved'))== 0 ? 0 : number_format(count($off->where('status', 'Approved'))/count($off),2)*100;
                                                    $total_u_click += (int)count($off->where('unique_', 1));
                                                    $total_ecpm += (int)number_format($total_earning / count($off), 2);
                                            ?>
                                         <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                      
                                        <td><?php echo e($total_clck); ?></td>
                                        <td><?php echo e($total_lead); ?></td>
                                        <td><?php echo e(number_format($total_earning,2)); ?></td>
                                         <td><?php echo e($total_u_click); ?></td>
                                          <td><?php echo e($total_clck*100); ?>%</td>
                                        <td><?php echo e($total_cvr); ?>%</td>
                                       
                                        <td>€ <?php echo e($total_ecpm); ?></td>

                                    </tr>
                                    </tbody>
                                </table>

                            </div>


                            <div class="row" style="overflow-x: auto;">
                                <h6>Detailed Report </h6>

                                <table class="table table-bordered table-striped dt-responsive nowrap"
                                       style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                                    <thead class="thead thead-light">
                                    <tr>
                                        <th>Offer Name</th>
                                        <th>Click</th>
                                        <th>Leads</th>
                                        <th>Earning</th>
                                        <th>CR</th>
                                        <th>CVR</th>
                                        <th>Unique Click</th>
                                        <th>ECPM</th>
                                    </tr>
                                    </thead>
                                    <tbody class="text-dark">
                                        <?php $__currentLoopData = $offer; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=> $off): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td> <?php echo e($off[0]->offer_name); ?></td>
                                            <td> <?php echo e(count($off)); ?></td>
                                            <td><?php echo e(count($off->where('status', 'Approved'))); ?></td>
                                            <td>
                                                <?php
                                                $total = 0;
                                                    foreach($off->where('status', 'Approved') as $offs){
                                                        $total += $offs->payout;
                                                    }
                                                    echo number_format($total,2);
                                                    
                                                ?>
                                            </td>
                                            <td><?php echo e(count($off)*100); ?> %</td>
                                            <td><?php echo e(count($off->where('status', 'Approved'))== 0 ? 0 : number_format(count($off->where('status', 'Approved'))/count($off),2)*100); ?>%</td>
                                            <td><?php echo e(count($off->where('unique_', 1))); ?></td>
                                            <td><?php if($total > 0): ?> € <?php echo e(number_format($total / count($off), 2)); ?> <?php else: ?> 0 <?php endif; ?></td>
                                            
                                        </tr>
                                           
                                         
                                           
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>

                            </div>


                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
    <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
            crossorigin="anonymous"></script>
    <script type="text/javascript" src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/jquery.mark.min.js">
    </script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.bootstrap4.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.buttons.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/buttons.bootstrap4.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.keyTable.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.select.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/buttons.html5.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/buttons.print.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/dataTables.responsive.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/responsive.bootstrap4.min.js"></script>
    <script src="<?php echo e(config('app.url')); ?>/public/public/vendors/datatables/datatables.mark.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
    <script type="text/javascript">
        <?php $site = DB::table('site_settings')->first(); ?>
        $(function() {

            $(function() {
                $('.selectpicker').selectpicker();
            });


            $('#description').summernote({
                height: 150
            });
            $('#requirements').summernote({
                height: 150
            });
            $('.js-example-basic-multiple').select2();

            <?php if(Session::has('success')): ?>
            Swal.fire({
                title: '<?php echo e(Session::get('success')); ?>',


                confirmButtonText: 'Ok'
            })
            <?php endif; ?>

            $('#payout').change(function() {
                if ($('#payout').val() == 'fixed') {
                    $('#payout_amount').removeAttr('disabled', 'true');
                    $('#payout_amount').val('');
                } else {


                    $('#payout_amount').attr('disabled', 'true');


                }
            })
            $('select[name=offer_type]').change(function(e) {
                if ($('select[name=offer_type]').val() == 'special') {
                    $('.divhide').removeClass('d-none');


                } else {

                    $('.divhide').addClass('d-none');

                }
            })
            var offer_table = $('#offer_table').DataTable({

                "mark": true,

                "order": [

                    [0, "desc"]

                ],

                "columnDefs": [

                    {

                        "targets": [0],

                        "render": function(data, type, row, meta) {

                            return '#' + data;

                        }

                    },

                    {

                        "responsivePriority": 1,

                        "targets": 0

                    },

                    {

                        "responsivePriority": 2,

                        "targets": -1,

                        "orderable": false

                    }

                ],

                "processing": true,

                "serverSide": true,

                "ajax": {

                    url: "<?php echo e(route('admin.show-offers')); ?>",
                    "data": function(d) {
                        d.offer_name = $('#offer_name').val();
                        d.offer_id = $('#offer_id').val();
                        d.countries = $('#countries').val();
                        d.ua_target = $('#ua_target').val();
                        d.traffic = $('#traffic').val();
                        d.status = $('#status').val();
                        d.offer_type = $('#offer_type').val();
                    },
                    error: function(xhr) {

                        session_error(xhr);

                        // console.log(xhr.status);

                    }

                },

                "columns": [

                    {
                        "data": "id"
                    },

                    {
                        "data": "offer_name"
                    },
                    {
                        "data": "category.category_name"
                    },
                    {
                        "data": "countries"
                    },

                    {
                        "data": "payout_type"
                    },
                    {
                        "data": "payout"
                    },
                    {
                        "data": "browsers"
                    },
                    {
                        "data": "ua_target"
                    },

                    {
                        "data": "status"
                    },
                    {
                        "data": "offer_type"
                    },
                    {
                        "data": "clicks"
                    },
                    {
                        "data": "conversion"
                    },

                    {
                        "data": "smartlinkstatus"
                    },


                    {
                        "data": "action"
                    }

                ],

                drawCallback: function(settings) {

                    $(document).find('[data-toggle="tooltip"]').tooltip();

                },

                initComplete: function(settings, json) {

                    // $(document).find('[data-toggle="tooltip"]').tooltip();

                }

            })
            $('#offer_table').on('click', '.deleteData', function() {
                let id = $(this).attr('data-id');
                Swal.fire({
                    title: 'Are you sure?',
                    text: "You want to remove this Offer ",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, remove it!'
                }).then((result) => {
                    if (result.value) {
                        $.ajax({
                            url: "<?php echo e(route('admin.delete-offer')); ?>",
                            type: 'GET',
                            dataType: 'JSON',
                            data: {
                                id: id
                            },
                            success: function(result) {
                                $('.loader').fadeOut();
                                // console.log(result);
                                if (!result.status) {
                                    Swal.fire('Failed', result.message, 'error');

                                } else {
                                    Swal.fire('Success', result.message, 'success');

                                    location.reload();

                                }
                            },
                            error: function(xhr) {
                                $('.loader').fadeOut();
                                if (xhr.status == 422) {
                                    $.each(xhr.responseJSON.errors, function(k, v) {
                                        form.find('[name="' + k + '"]').after(
                                            '<div class="text-danger">' + v[
                                                0] +
                                            '</div>');
                                    });
                                } else if (xhr.status == 419) {
                                    window.location.href = "";
                                }
                                // console.log(xhr);
                            }
                        });
                    }
                });
            });

        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout.admin-dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ayixmwuy/public_html/aff/backend/resources/views/admin/offer/view_offer_report_s.blade.php ENDPATH**/ ?>