Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ReportController | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| export | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Influencer; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Models\Order; |
| 7 | use App\Services\ReportExportService; |
| 8 | use Illuminate\Http\Request; |
| 9 | |
| 10 | class ReportController extends Controller |
| 11 | { |
| 12 | public function export(Request $request, ReportExportService $exporter) |
| 13 | { |
| 14 | $influencer = $request->user()->influencer; |
| 15 | $rows = Order::with('commission') |
| 16 | ->where('influencer_id', $influencer->id) |
| 17 | ->latest('placed_at') |
| 18 | ->get() |
| 19 | ->map(fn ($order) => [ |
| 20 | $order->order_number, |
| 21 | $order->placed_at?->format('d/m/Y H:i'), |
| 22 | $order->status->label(), |
| 23 | number_format((float) $order->commission_base_amount, 2, ',', '.'), |
| 24 | number_format((float) ($order->commission?->commission_amount ?? 0), 2, ',', '.'), |
| 25 | ]); |
| 26 | |
| 27 | $headers = ['Pedido', 'Data', 'Status', 'Valor considerado', 'Comissão']; |
| 28 | return $request->query('format') === 'excel' |
| 29 | ? $exporter->excel('meu-relatorio.xls', $headers, $rows) |
| 30 | : $exporter->csv('meu-relatorio.csv', $headers, $rows); |
| 31 | } |
| 32 | } |