diff --git a/database/migrations/2026_06_19_225430_update_invoice_recipient.php b/database/migrations/2026_06_19_225430_update_invoice_recipient.php index 0f3e0fd7..8f042373 100644 --- a/database/migrations/2026_06_19_225430_update_invoice_recipient.php +++ b/database/migrations/2026_06_19_225430_update_invoice_recipient.php @@ -11,8 +11,20 @@ return new class extends Migration */ public function up(): void { - if (\DB::table('invoices')->count()) { - throw new \Exception('Migration not possibue for current bills.'); + foreach (DB::table('invoices')->get() as $invoice) { + $to = json_decode($invoice->to); + $position = DB::table('invoice_positions')->where('invoice_id', $invoice->id)->first(); + + if ($position) { + $member = DB::table('members')->where('id', $position->member_id)->first(); + if ($member) { + $to->email = $member->email_parents ?: $member->email; + } + } + + $to->greeting = 'Liebe '.$to->name; + + DB::table('invoices')->where('id', $invoice->id)->update(['to' => json_encode($to)]); } Schema::table('invoices', function (Blueprint $table) {