request = $request; } public function execute() : UpdateInvoiceResponse { $response = new UpdateInvoiceResponse(); $changes = $this->request->invoice->changes ?? ''; if ($this->request->invoice->amount !== $this->request->amount->getAmount()) { $changes .= 'Betrag geändert von ' . Amount::fromString($this->request->invoice->amount)->toString() . ' auf ' . Amount::fromString($this->request->amount->getAmount())->toString() . '.
'; $this->request->invoice->amount = $this->request->amount->getAmount(); } if ($this->request->invoice->invoiceType()->slug !== $this->request->invoiceType->slug) { $changes .= 'Abrechnungstyp geändert von ' . $this->request->invoice->invoiceType()->name . ' auf ' . $this->request->invoiceType->name . '.
'; $this->request->invoice->type = $this->request->invoiceType->slug; } if ($this->request->invoice->costUnit()->first()->id !== $this->request->costUnit->id) { $changes .= 'Kostenstelle geändert von ' . $this->request->invoice->costUnit()->first()->name . ' auf ' . $this->request->costUnit->name . '.
'; $this->request->invoice->cost_unit_id = $this->request->costUnit->id; } $purpose = trim((string) $this->request->purpose); $purpose = $purpose === '' ? null : $purpose; // Verglichen wird gegen den angezeigten Text, nicht gegen die Spalte: Das Formular ist damit // vorbelegt, und wer ihn unverändert abschickt, hat nichts geändert. Ein Bestandsbeleg behält so // seine leere Spalte und damit die Ableitung; wer das Feld leert, schaltet zurück auf automatisch. if (($purpose ?? '') !== $this->request->invoice->purposeText()) { $changes .= 'Zahlungsgrund geändert von ' . $this->request->invoice->purposeText() . ' auf ' . ($purpose ?? '--') . '.
'; $this->request->invoice->purpose = $purpose; } $this->request->invoice->comment = $this->request->comment; $this->request->invoice->changes = $changes; $this->request->invoice->save(); $request = new ChangeStatusRequest($this->request->invoice, InvoiceStatus::INVOICE_STATUS_APPROVED); $changeStatusCommand = new ChangeStatusCommand($request); $changeStatusCommand->execute(); return $response; } }