Operation processes on invoices
This commit is contained in:
27
app/Domains/Invoice/Controllers/ChangeStateController.php
Normal file
27
app/Domains/Invoice/Controllers/ChangeStateController.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Controllers;
|
||||
|
||||
use App\Domains\Invoice\Actions\ChangeStatus\ChangeStatusCommand;
|
||||
use App\Domains\Invoice\Actions\ChangeStatus\ChangeStatusRequest;
|
||||
use App\Scopes\CommonController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ChangeStateController extends CommonController
|
||||
{
|
||||
public function __invoke(int $invoiceId, string $newState) : JsonResponse {
|
||||
$invoice = $this->invoices->getAsTreasurer($invoiceId);
|
||||
if ($invoice === null) {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$comment = request()->get('reason') ?? null;
|
||||
$changeStatusRequest = new ChangeStatusRequest($invoice, $newState, $comment);
|
||||
$changeStatusCommand = new ChangeStatusCommand($changeStatusRequest);
|
||||
if ($changeStatusCommand->execute()->success) {
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
return response()->json([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user