diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index cb8327e..9a038af 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -23,6 +23,31 @@ class ReportController extends Controller ->groupBy('expense_category') ->get(); + // 2.5 Ingresos por Categoría (Para Pie Chart) + $rawEarningsByCategory = \App\Models\SaleDetail::join('products', 'sale_details.product_id', '=', 'products.id') + ->select('products.type', DB::raw('SUM(sale_details.quantity * sale_details.price) as total_earnings')) + ->groupBy('products.type') + ->get(); + + $categoryTranslations = [ + 'bike' => 'Bicicletas', + 'clothing' => 'Indumentaria', + 'accessory' => 'Accesorios', + 'spare' => 'Repuestos', + 'children' => 'Niños', + 'rollers' => 'Rollers', + 'skate' => 'Skates', + 'other' => 'Otros' + ]; + + $earningsByCategory = $rawEarningsByCategory->map(function($item) use ($categoryTranslations) { + $type = $item->type; + return [ + 'category' => $categoryTranslations[$type] ?? ucfirst($type), + 'total' => $item->total_earnings + ]; + }); + // 3. Ingresos y Egresos por Mes (Últimos 6 meses) $months = []; $monthlyIncomeData = []; @@ -81,6 +106,7 @@ class ReportController extends Controller 'totalOutcome', 'balance', 'expensesByCategory', + 'earningsByCategory', 'months', 'monthlyIncomeData', 'monthlyOutcomeData', diff --git a/resources/views/reports/index.blade.php b/resources/views/reports/index.blade.php index 49982ed..edc5f11 100644 --- a/resources/views/reports/index.blade.php +++ b/resources/views/reports/index.blade.php @@ -50,19 +50,27 @@ - + +