input('report_date', Carbon::today()->toDateString()); // Fetch dynamic payment options using DB facade since the model is missing in this branch $paymentOptions = DB::table('payment_options')->where('is_active', 1) ->orderBy('id') ->get(['id', 'name']); $sales = DB::table('sales') ->leftJoin('users', 'sales.user_id', '=', 'users.id') ->leftJoin('customers', 'sales.customer_id', '=', 'customers.id') ->whereDate('sales.created_at', $report_date) ->select( 'sales.id', 'sales.created_at as date', 'sales.reference_no', 'users.name as cashier', 'customers.name as customer', 'sales.grand_total', 'sales.due_amount' )->get(); $sales_data = []; foreach ($sales as $sale) { // Get payments ONLY made on the report_date $payments = DB::table('payments') ->where('sale_id', $sale->id) ->whereDate('created_at', $report_date) ->select('payment_option_id', DB::raw('SUM(amount) as total_amount')) ->groupBy('payment_option_id') ->get(); $methodTotals = []; foreach ($payments as $payment) { $methodTotals[$payment->payment_option_id] = $payment->total_amount; } $sales_data[] = (object) [ 'date' => Carbon::parse($sale->date)->format('Y-m-d'), 'reference_no' => $sale->reference_no, 'cashier' => $sale->cashier ?? 'N/A', 'customer' => $sale->customer ?? 'N/A', 'grand_total' => $sale->grand_total, 'due_amount' => $sale->due_amount, 'methods' => $methodTotals ]; } return view('dailysalepaymentreportmodule::index', compact('sales_data', 'report_date', 'paymentOptions')); } /** * Show the form for creating a new resource. * @return Renderable */ public function create() { return view('dailysalepaymentreportmodule::create'); } /** * Store a newly created resource in storage. * @param Request $request * @return Renderable */ public function store(Request $request) { // } /** * Show the specified resource. * @param int $id * @return Renderable */ public function show($id) { return view('dailysalepaymentreportmodule::show'); } /** * Show the form for editing the specified resource. * @param int $id * @return Renderable */ public function edit($id) { return view('dailysalepaymentreportmodule::edit'); } /** * Update the specified resource in storage. * @param Request $request * @param int $id * @return Renderable */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * @param int $id * @return Renderable */ public function destroy($id) { // } public function exportReport(Request $request) { $date = $request->query('date'); $type = $request->query('type'); return "Export function is working. Selected Date: " . $date . " | Export Type: " . $type; } }