<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        // A cash overpayment is tendered above the payable figure and the
        // excess handed back. The settlement splits are capped at the balance
        // (PaymentService rejects over-splits), so without these two snapshots
        // the receipt could only ever show the settled portion — never what the
        // customer actually handed over or the change they received back.
        Schema::table('invoices', function (Blueprint $table) {
            $table->decimal('tendered_amount', 14, 2)->nullable()->after('paid_amount');
            $table->decimal('change_amount', 14, 2)->nullable()->after('tendered_amount');
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropColumn(['tendered_amount', 'change_amount']);
        });
    }
};
