- Agregado grafico de torta de "Ingresos por categoria" para mayor utiidad de los reportes.
This commit is contained in:
Bryam105
2026-06-12 09:09:19 -03:00
parent 2454ee3a23
commit cf130fe7cb
2 changed files with 84 additions and 7 deletions
+26
View File
@@ -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',