FleetCart/Modules/Report/ShippingReport.php

37 lines
940 B
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Report;
use Modules\Order\Entities\Order;
use Modules\Shipping\Facades\ShippingMethod;
class ShippingReport extends Report
{
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');
}
2023-12-03 14:07:47 +00:00
protected function view()
{
return 'report::admin.reports.shipping_report.index';
}
protected function data()
{
return [
'shippingMethods' => ShippingMethod::all(),
];
}
2023-06-11 12:14:03 +00:00
}