<?php $__env->startSection('title', translate('Earning Report')); ?>

<?php $__env->startPush('css_or_js'); ?>
    <style>
        .chartjs-custom{
            height: 18rem;
        }
    </style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="content container-fluid">
        <div class="page-header">
            <div class="media align-items-center mb-2">
                <div class="">
                    <img src="<?php echo e(asset('public/assets/admin/img/image-4.png')); ?>" class="w--20" alt="">
                </div>

                <div class="media-body pl-3">
                    <div class="row">
                        <div class="col-lg mb-3 mb-lg-0 text-capitalize">
                            <h1 class="page-header-title"><?php echo e(translate('earning')); ?> <?php echo e(translate('report')); ?> <?php echo e(translate('overview')); ?></h1>

                            <div class="row align-items-center">
                                <div class="col-auto">
                                    <span><?php echo e(translate('admin')); ?>:</span>
                                    <a href="#"  class="text--primary-2"><?php echo e(auth('admin')->user()->f_name.' '.auth('admin')->user()->l_name); ?></a>
                                </div>

                                <div class="col-auto">
                                    <div class="row align-items-center g-0 m-0">
                                        <div class="col-auto pr-2"><?php echo e(translate('date :')); ?></div>
                                        <div class="text--primary-2">
                                            <?php echo e(session('from_date')); ?> - <?php echo e(session('to_date')); ?>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>

        <div class="card">
            <div class="card-body">
                <form action="<?php echo e(route('admin.report.set-date')); ?>" method="post">
                    <?php echo csrf_field(); ?>
                    <div class="row g-3">
                        <div class="col-12">
                            <div>
                                <label class="form-label mb-0 font-semibold"><?php echo e(translate('show')); ?> <?php echo e(translate('data')); ?> <?php echo e(translate('by')); ?> <?php echo e(translate('date')); ?>

                                    <?php echo e(translate('range')); ?></label>
                            </div>
                        </div>
                        <div class="col-md-4 col-sm-6">
                            <label class="input-label"><?php echo e(translate('start')); ?> <?php echo e(translate('date')); ?></label>
                            <label class="input-date">
                                <input type="text" name="from" id="from_date"
                                       class="js-flatpickr form-control flatpickr-custom flatpickr-input" placeholder="<?php echo e(translate('dd/mm/yy')); ?>" required>
                            </label>
                        </div>
                        <div class="col-md-4 col-sm-6">
                            <label class="input-label"><?php echo e(translate('end')); ?> <?php echo e(translate('date')); ?></label>
                            <label class="input-date">
                                <input type="text" name="to" id="to_date"
                                       class="js-flatpickr form-control flatpickr-custom flatpickr-input" placeholder="<?php echo e(translate('dd/mm/yy')); ?>" required>
                            </label>
                        </div>
                        <div class="col-md-4">
                            <label class="input-label d-none d-md-block">&nbsp;</label>
                            <div>
                                <button type="submit" class="btn btn--primary min-h-45px btn-block"><?php echo e(translate('show')); ?></button>
                            </div>
                        </div>
                    </div>
                </form>

                <div class="row g-3 mt-3">
                    <?php
                        $from = session('from_date');
                        $to = session('to_date');
                        $totalTax=\App\Model\Order::where(['order_status'=>'delivered'])
                            ->whereBetween('created_at', [$from, $to])
                            ->sum('total_tax_amount');

                        if($totalTax==0){
                            $totalTax=0.01;
                        }

                        $totalDeliveryCharge=\App\Model\Order::where(['order_status'=>'delivered'])
                            ->whereBetween('created_at', [$from, $to])
                            ->sum('delivery_charge');

                        if($totalDeliveryCharge==0){
                            $totalDeliveryCharge=0.01;
                        }

                        $totalSold=\App\Model\Order::where(['order_status'=>'delivered'])
                            ->whereBetween('created_at', [$from, $to])
                            ->sum('order_amount');

                        if($totalSold==0){
                            $totalSold=.01;
                        }

                        $totalEarning = $totalSold - $totalTax - $totalDeliveryCharge;
                    ?>
                    <div class="col-sm-6">
                        <div class="card card-sm bg--2 border-0 shadow-none">
                            <div class="card-body py-5 px-xl-5">
                                <div class="row">
                                    <div class="col">
                                        <div class="media">
                                            <i class="tio-dollar-outlined nav-icon"></i>
                                            <div class="media-body">
                                                <h4 class="mb-1"><?php echo e(translate('total')); ?> <?php echo e(translate('sold')); ?></h4>
                                                <span class="text-success">
                                                <i class="tio-trending-up"></i> <?php echo e(Helpers::set_symbol(round(abs($totalSold)))); ?>

                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-auto">
                                        <div class="js-circle"
                                            data-hs-circles-options='{
                                            "value": <?php echo e($totalSold=='.01'?0:round(($totalSold/$totalSold)*100)); ?>,
                                            "maxValue": 100,
                                            "duration": 2000,
                                            "isViewportInit": true,
                                            "colors": ["#00800040", "green"],
                                            "radius": 25,
                                            "width": 3,
                                            "fgStrokeLinecap": "round",
                                            "textFontSize": 14,
                                            "additionalText": "%",
                                            "textClass": "circle-custom-text",
                                            "textColor": "green"
                                            }'>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="card card-sm bg--3 border-0 shadow-none">
                            <div class="card-body py-5 px-xl-5">
                                <div class="row">
                                    <div class="col">
                                        <div class="media">
                                            <i class="tio-money nav-icon"></i>
                                            <div class="media-body">
                                                <h4 class="mb-1"><?php echo e(translate('total')); ?> <?php echo e(translate('tax')); ?></h4>
                                                <span class="text-danger">
                                                <i class="tio-trending-up"></i> <?php echo e(Helpers::set_symbol(round(abs($totalTax)))); ?>

                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-auto">
                                        <div class="js-circle"
                                            data-hs-circles-options='{
                                "value": <?php echo e($totalTax=='0.01'?0:round(((abs($totalTax))/$totalSold)*100)); ?>,
                                "maxValue": 100,
                                "duration": 2000,
                                "isViewportInit": true,
                                "colors": ["#f83b3b40", "#f83b3b"],
                                "radius": 25,
                                "width": 3,
                                "fgStrokeLinecap": "round",
                                "textFontSize": 14,
                                "additionalText": "%",
                                "textClass": "circle-custom-text",
                                "textColor": "#f83b3b"
                                }'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="card card-sm bg--4 border-0 shadow-none">
                            <div class="card-body py-5 px-xl-5">
                                <div class="row">
                                    <div class="col">
                                        <div class="media">
                                            <i class="tio-money nav-icon"></i>

                                            <div class="media-body">
                                                <h4 class="mb-1"><?php echo e(translate('total')); ?> <?php echo e(translate('delivery')); ?> <?php echo e(translate('charge')); ?></h4>
                                                <span class="text-warning">
                                                <i class="tio-trending-up"></i> <?php echo e(Helpers::set_symbol(round(abs($totalDeliveryCharge)))); ?>

                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-auto">
                                        <div class="js-circle"
                                            data-hs-circles-options='{
                                "value": <?php echo e($totalDeliveryCharge=='0.01'?0:round(((abs($totalDeliveryCharge))/$totalSold)*100)); ?>,
                                "maxValue": 100,
                                "duration": 2000,
                                "isViewportInit": true,
                                "colors": ["#ec9a3c40", "#ec9a3c"],
                                "radius": 25,
                                "width": 3,
                                "fgStrokeLinecap": "round",
                                "textFontSize": 14,
                                "additionalText": "%",
                                "textClass": "circle-custom-text",
                                "textColor": "#ec9a3c"
                                }'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="card card-sm bg--1 border-0 shadow-none">
                            <div class="card-body py-5 px-xl-5">
                                <div class="row">
                                    <div class="col">
                                        <div class="media">
                                            <i class="tio-money nav-icon"></i>
                                            <div class="media-body">
                                                <h4 class="mb-1"><?php echo e(translate('total')); ?> <?php echo e(translate('earning')); ?></h4>
                                                <span class="text-warning">
                                                <i class="tio-trending-up"></i> <?php echo e(Helpers::set_symbol(round(abs($totalEarning)))); ?>

                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-auto">
                                        <div class="js-circle"
                                            data-hs-circles-options='{
                                "value": <?php echo e($totalEarning=='0.01'?0:round(((abs($totalEarning))/$totalSold)*100)); ?>,
                                "maxValue": 100,
                                "duration": 2000,
                                "isViewportInit": true,
                                "colors": ["#0096ff40", "#0096ff90"],
                                "radius": 25,
                                "width": 3,
                                "fgStrokeLinecap": "round",
                                "textFontSize": 14,
                                "additionalText": "%",
                                "textClass": "circle-custom-text",
                                "textColor": "#0096ff"
                                }'></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card mt-3">
            <div class="card-header">
                <?php
                    $totalSold=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [date('y-01-01'), date('y-12-31')])->sum('order_amount')
                ?>
                <h6 class="card-subtitle mb-0"><?php echo e(translate('Total sale of ')); ?> <?php echo e(date('Y')); ?> :<span
                        class="h3 ml-sm-2"> <?php echo e(Helpers::set_symbol($totalSold)); ?></span>
                </h6>
            </div>

        <?php
            $sold=[];
                for ($i=1;$i<=12;$i++){
                    $from = date('Y-'.$i.'-01');
                    $to = date('Y-'.$i.'-30');
                    $sold[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('order_amount');
                }
        ?>

        <?php
            $tax=[];
                for ($i=1;$i<=12;$i++){
                    $from = date('Y-'.$i.'-01');
                    $to = date('Y-'.$i.'-30');
                    $tax[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('total_tax_amount');
                }
        ?>

        <?php
            $deliveryCharge=[];
                for ($i=1;$i<=12;$i++){
                    $from = date('Y-'.$i.'-01');
                    $to = date('Y-'.$i.'-30');
                    $deliveryCharge[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('delivery_charge');
                }
        ?>

        <?php
            $soldCal=[];
            $taxCal=[];
            $deliveryCharge_cal=[];
            $earning=[];
            for ($i=1;$i<=12;$i++){
                $from = date('Y-'.$i.'-01');
                $to = date('Y-'.$i.'-30');
                $soldCal[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('order_amount');
                $taxCal[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('total_tax_amount');
                $deliveryCharge_cal[$i]=\App\Model\Order::where(['order_status'=>'delivered'])->whereBetween('created_at', [$from, $to])->sum('delivery_charge');
                $earning[$i] = $soldCal[$i] - $taxCal[$i] - $deliveryCharge_cal[$i];
            }
        ?>

        <?php ($currency_position = Helpers::get_business_settings('currency_symbol_position')); ?>

            <div class="card-body">
                <div class="chartjs-custom">
                    <canvas class="js-chart"
                            data-hs-chartjs-options='{
                        "type": "line",
                        "data": {
                           "labels": ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
                           "datasets": [{
                            "data": [<?php echo e($sold[1]); ?>,<?php echo e($sold[2]); ?>,<?php echo e($sold[3]); ?>,<?php echo e($sold[4]); ?>,<?php echo e($sold[5]); ?>,<?php echo e($sold[6]); ?>,<?php echo e($sold[7]); ?>,<?php echo e($sold[8]); ?>,<?php echo e($sold[9]); ?>,<?php echo e($sold[10]); ?>,<?php echo e($sold[11]); ?>,<?php echo e($sold[12]); ?>],
                            "backgroundColor": ["rgba(55, 125, 255, 0)", "rgba(255, 255, 255, 0)"],
                            "borderColor": "green",
                            "borderWidth": 2,
                            "pointRadius": 0,
                            "pointBorderColor": "#fff",
                            "pointBackgroundColor": "green",
                            "pointHoverRadius": 0,
                            "hoverBorderColor": "#fff",
                            "hoverBackgroundColor": "#377dff"
                          },

                          {
                            "data": [<?php echo e($tax[1]); ?>,<?php echo e($tax[2]); ?>,<?php echo e($tax[3]); ?>,<?php echo e($tax[4]); ?>,<?php echo e($tax[5]); ?>,<?php echo e($tax[6]); ?>,<?php echo e($tax[7]); ?>,<?php echo e($tax[8]); ?>,<?php echo e($tax[9]); ?>,<?php echo e($tax[10]); ?>,<?php echo e($tax[11]); ?>,<?php echo e($tax[12]); ?>],
                            "backgroundColor": ["rgba(0, 201, 219, 0)", "rgba(255, 255, 255, 0)"],
                            "borderColor": "#f83b3b",
                            "borderWidth": 2,
                            "pointRadius": 0,
                            "pointBorderColor": "#fff",
                            "pointBackgroundColor": "#f83b3b",
                            "pointHoverRadius": 0,
                            "hoverBorderColor": "#fff",
                            "hoverBackgroundColor": "#f83b3b"
                          },
                          {
                            "data": [<?php echo e($deliveryCharge[1]); ?>,<?php echo e($deliveryCharge[2]); ?>,<?php echo e($deliveryCharge[3]); ?>,<?php echo e($deliveryCharge[4]); ?>,<?php echo e($deliveryCharge[5]); ?>,<?php echo e($deliveryCharge[6]); ?>,<?php echo e($deliveryCharge[7]); ?>,<?php echo e($deliveryCharge[8]); ?>,<?php echo e($deliveryCharge[9]); ?>,<?php echo e($deliveryCharge[10]); ?>,<?php echo e($deliveryCharge[11]); ?>,<?php echo e($deliveryCharge[12]); ?>],
                            "backgroundColor": ["rgba(0, 201, 219, 0)", "rgba(255, 255, 255, 0)"],
                            "borderColor": "#f5a200",
                            "borderWidth": 2,
                            "pointRadius": 0,
                            "pointBorderColor": "#fff",
                            "pointBackgroundColor": "#f5a200",
                            "pointHoverRadius": 0,
                            "hoverBorderColor": "#fff",
                            "hoverBackgroundColor": "#f5a200"
                          },
                          {
                            "data": [<?php echo e($earning[1]); ?>,<?php echo e($earning[2]); ?>,<?php echo e($earning[3]); ?>,<?php echo e($earning[4]); ?>,<?php echo e($earning[5]); ?>,<?php echo e($earning[6]); ?>,<?php echo e($earning[7]); ?>,<?php echo e($earning[8]); ?>,<?php echo e($earning[9]); ?>,<?php echo e($earning[10]); ?>,<?php echo e($earning[11]); ?>,<?php echo e($earning[12]); ?>],
                            "backgroundColor": ["rgba(0, 201, 219, 0)", "rgba(255, 255, 255, 0)"],
                            "borderColor": "#0096ff",
                            "borderWidth": 2,
                            "pointRadius": 0,
                            "pointBorderColor": "#fff",
                            "pointBackgroundColor": "#0096ff",
                            "pointHoverRadius": 0,
                            "hoverBorderColor": "#fff",
                            "hoverBackgroundColor": "#0096ff"
                          }]
                        },
                        "options": {
                          "gradientPosition": {"y1": 200},
                           "scales": {
                              "yAxes": [{
                                "gridLines": {
                                  "color": "#e7eaf3",
                                  "drawBorder": false,
                                  "zeroLineColor": "#e7eaf3"
                                },
                                "ticks": {
                                  "min": 0,
                                  "max": <?php echo e(\App\CentralLogics\Helpers::max_earning()); ?>,
                                  "stepSize": <?php echo e(round(\App\CentralLogics\Helpers::max_earning()/5)); ?>,
                                  "fontColor": "#97a4af",
                                  "fontFamily": "Open Sans, sans-serif",
                                  "padding": 10,
                                  "<?php echo e($currency_position == 'left' ? 'prefix' : 'postfix'); ?>": " <?php echo e(\App\CentralLogics\Helpers::currency_symbol()); ?>"
                                }
                              }],
                              "xAxes": [{
                                "gridLines": {
                                  "display": false,
                                  "drawBorder": false
                                },
                                "ticks": {
                                  "fontSize": 12,
                                  "fontColor": "#97a4af",
                                  "fontFamily": "Open Sans, sans-serif",
                                  "padding": 5
                                }
                              }]
                          },
                          "tooltips": {
                            "prefix": "",
                            "postfix": "",
                            "hasIndicator": true,
                            "mode": "index",
                            "intersect": false,
                            "lineMode": true,
                            "lineWithLineColor": "rgba(19, 33, 68, 0.075)"
                          },
                          "hover": {
                            "mode": "nearest",
                            "intersect": true
                          }
                        }
                      }'>
                    </canvas>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script'); ?>

<?php $__env->stopPush(); ?>

<?php $__env->startPush('script_2'); ?>

    <script src="<?php echo e(asset('public/assets/admin')); ?>/vendor/chart.js/dist/Chart.min.js"></script>
    <script
        src="<?php echo e(asset('public/assets/admin')); ?>/vendor/chartjs-chart-matrix/dist/chartjs-chart-matrix.min.js"></script>
    <script src="<?php echo e(asset('public/assets/admin')); ?>/js/hs.chartjs-matrix.js"></script>
    <script src="<?php echo e(asset('public/assets/admin/js/flatpicker.js')); ?>"></script>
    <script src="<?php echo e(asset('public/assets/admin/js/earning.js')); ?>"></script>

    <script>
        $('#from_date,#to_date').change(function () {
            let fr = $('#from_date').val();
            let to = $('#to_date').val();
            if (fr != '' && to != '') {
                if (fr > to) {
                    $('#from_date').val('');
                    $('#to_date').val('');
                    toastr.error('<?php echo e(translate("Invalid date range!")); ?>', Error, {
                        CloseButton: true,
                        ProgressBar: true
                    });
                }
            }
        })
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/mimeld/admin.mxepto.mimeld.com/resources/views/admin-views/report/earning-index.blade.php ENDPATH**/ ?>