loadMissing(['lines', 'location']); if (! $sale->customer_email) { $sale->forceFill(['customer_email' => $email])->save(); } try { Mail::to($email)->send(new DigitalReceiptMail($sale)); } catch (\Throwable $e) { Log::warning('pos.receipt_email_failed', [ 'sale_id' => $sale->id, 'email' => $email, 'error' => $e->getMessage(), ]); throw new RuntimeException('Could not send the receipt email. Please try again.'); } return [ 'ok' => true, 'message' => 'Receipt sent to '.$email, ]; } /** * Best-effort send after a paid sale when an email is already on the sale. */ public function sendIfPresent(PosSale $sale): bool { $email = trim((string) ($sale->customer_email ?? '')); if ($email === '') { return false; } try { $this->send($sale, $email); return true; } catch (\Throwable $e) { Log::info('pos.receipt_email_skipped', [ 'sale_id' => $sale->id, 'error' => $e->getMessage(), ]); return false; } } }