MOON
Server: Apache
System: Linux server.royaltuning.hu 4.18.0-425.13.1.el8_7.x86_64 #1 SMP Tue Feb 21 04:20:52 EST 2023 x86_64
User: royaltuning (1001)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/local/apache/htdocs/Modules/Report/ShippingReport.php
<?php

namespace Modules\Report;

use Modules\Order\Entities\Order;
use Modules\Shipping\Facades\ShippingMethod;

class ShippingReport extends Report
{
    protected function view()
    {
        return 'report::admin.reports.shipping_report.index';
    }

    protected function data()
    {
        return [
            'shippingMethods' => ShippingMethod::all(),
        ];
    }

    public function query()
    {
        return Order::select('shipping_method')
            ->selectRaw('MIN(created_at) as start_date')
            ->selectRaw('MAX(created_at) as end_date')
            ->selectRaw('COUNT(*) as total_orders')
            ->selectRaw('SUM(shipping_cost) as total')
            ->when(request()->has('shipping_method'), function ($query) {
                $query->where('shipping_method', request('shipping_method'));
            })
            ->groupBy('shipping_method');
    }
}