Files
mareike/app/Domains/Event/Controllers/BankStatementParseController.php
T
2026-09-09 16:55:08 +02:00

44 lines
1.6 KiB
PHP

<?php
namespace App\Domains\Event\Controllers;
use App\Domains\Event\Actions\ParseBankStatement\ParseBankStatementCommand;
use App\Domains\Event\Actions\ParseBankStatement\ParseBankStatementRequest;
use App\Models\PaymentMethod;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Nimmt den CSV-Export der Bank entgegen und liefert die Prüfansicht zurück. Gebucht wird hier nichts.
*/
class BankStatementParseController extends CommonController
{
public function __invoke(int $eventId, Request $request): JsonResponse
{
$event = $this->events->getById($eventId);
if ($event === null) {
return response()->json(['status' => 'error', 'message' => 'Die Veranstaltung wurde nicht gefunden.']);
}
// Das Kontoauszug-Format kommt vom Mandanten, nicht aus dem Event-Snapshot: Ein Bankwechsel
// muss sofort auch für laufende Aktionen gelten.
$configuration = $this->paymentMethods->tenantConfiguration(PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION);
$response = new ParseBankStatementCommand(new ParseBankStatementRequest(
event: $event,
file: $request->file('statement'),
configuration: $configuration,
))->execute();
return response()->json([
'status' => $response->success ? 'success' : 'error',
'message' => $response->message,
'rows' => $response->rows,
'participants' => $response->participants,
'skipped' => $response->skippedOlderThanWatermark,
]);
}
}