<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SaleController extends Controller
{
    public function dashboard() 
{
    // Mengambil data Summary sesuai urutan Spreadsheet A-AU
    $mainData = \App\Models\Sale::select(
            'admin_id', 
            'channel_id',
            \Illuminate\Support\Facades\DB::raw('SUM(qty_toples) as s_toples'),
            \Illuminate\Support\Facades\DB::raw('SUM(qty_mini) as s_mini'),
            \Illuminate\Support\Facades\DB::raw('SUM(qty_pouch) as s_pouch'),
            \Illuminate\Support\Facades\DB::raw('SUM(nominal_gmv) as s_gmv')
        )
        ->groupBy('admin_id', 'channel_id')
        ->with(['admin', 'channel'])
        ->get();

    $totalGmv = \App\Models\Sale::sum('nominal_gmv') ?? 0;

    return view('dashboard', compact('mainData', 'totalGmv'));
}
}
