NEW:
- Agregado grafico de torta de "Ingresos por categoria" para mayor utiidad de los reportes.
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user