Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ReportController | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| export | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Admin; |
| 4 | |
| 5 | use App\Enums\OrderStatus; |
| 6 | use App\Http\Controllers\Concerns\ResolvesContext; |
| 7 | use App\Http\Controllers\Controller; |
| 8 | use App\Models\Influencer; |
| 9 | use App\Models\Order; |
| 10 | use App\Services\ReportExportService; |
| 11 | use Illuminate\Http\Request; |
| 12 | use Illuminate\View\View; |
| 13 | |
| 14 | class ReportController extends Controller |
| 15 | { |
| 16 | use ResolvesContext; |
| 17 | |
| 18 | public function index(): View |
| 19 | { |
| 20 | $store = $this->currentStore(); |
| 21 | $ranking = Influencer::query() |
| 22 | ->where('store_id', $store->id) |
| 23 | ->withSum(['orders as paid_sales_sum' => fn ($q) => $q->where('status', OrderStatus::Paid->value)], 'commission_base_amount') |
| 24 | ->orderByDesc('paid_sales_sum') |
| 25 | ->limit(20) |
| 26 | ->get(); |
| 27 | |
| 28 | return view('admin.reports.index', compact('ranking')); |
| 29 | } |
| 30 | |
| 31 | public function export(Request $request, ReportExportService $exporter) |
| 32 | { |
| 33 | $store = $this->currentStore(); |
| 34 | $rows = Order::query() |
| 35 | ->with('influencer', 'commission') |
| 36 | ->where('store_id', $store->id) |
| 37 | ->latest('placed_at') |
| 38 | ->get() |
| 39 | ->map(fn ($order) => [ |
| 40 | $order->order_number, |
| 41 | $order->placed_at?->format('d/m/Y H:i'), |
| 42 | $order->influencer?->name, |
| 43 | $order->coupon_code_original, |
| 44 | $order->status->label(), |
| 45 | number_format((float) $order->commission_base_amount, 2, ',', '.'), |
| 46 | number_format((float) ($order->commission?->commission_amount ?? 0), 2, ',', '.'), |
| 47 | ]); |
| 48 | |
| 49 | $headers = ['Pedido', 'Data', 'Influencer', 'Cupom', 'Status', 'Base comissão', 'Comissão']; |
| 50 | return $request->query('format') === 'excel' |
| 51 | ? $exporter->excel('relatorio-pedidos.xls', $headers, $rows) |
| 52 | : $exporter->csv('relatorio-pedidos.csv', $headers, $rows); |
| 53 | } |
| 54 | } |