has('send_email') && $request->send_email == 'true') { $send_email = true; } $pdf = $request->client()->service()->statement( $request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table', 'status', 'show_credits_table']), $send_email ); if ($send_email) { return response()->json(['message' => ctrans('texts.email_queued')], 200); } if ($pdf) { return response()->streamDownload(function () use ($pdf) { echo $pdf; }, ctrans('texts.statement').'.pdf', ['Content-Type' => 'application/pdf']); } return response()->json(['message' => ctrans('texts.error_title')], 500); } }