52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Invoice\Actions\ChangeStatus;
|
|
|
|
use App\Enumerations\InvoiceStatus;
|
|
|
|
class ChangeStatusCommand {
|
|
private ChangeStatusRequest $request;
|
|
|
|
public function __construct(ChangeStatusRequest $request) {
|
|
$this->request = $request;
|
|
}
|
|
|
|
public function execute() : ChangeStatusResponse {
|
|
$response = new ChangeStatusResponse();
|
|
|
|
switch ($this->request->status) {
|
|
case InvoiceStatus::INVOICE_STATUS_APPROVED:
|
|
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_APPROVED;
|
|
$this->request->invoice->approved_by = auth()->user()->id;
|
|
$this->request->invoice->approved_at = now();
|
|
break;
|
|
|
|
case InvoiceStatus::INVOICE_STATUS_DENIED:
|
|
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_DENIED;
|
|
$this->request->invoice->denied_by = auth()->user()->id;
|
|
$this->request->invoice->denied_at = now();
|
|
$this->request->invoice->denied_reason = $this->request->comment;
|
|
break;
|
|
case InvoiceStatus::INVOICE_STATUS_NEW:
|
|
$this->request->invoice->status = InvoiceStatus::INVOICE_STATUS_NEW;
|
|
$this->request->invoice->approved_by = null;
|
|
$this->request->invoice->approved_at = null;
|
|
$this->request->invoice->denied_by = null;
|
|
$this->request->invoice->denied_at = null;
|
|
$this->request->invoice->comment = $this->request->invoice->denied_reason;
|
|
$this->request->invoice->denied_reason = null;
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($this->request->invoice->save()) {
|
|
$response->success = true;
|
|
}
|
|
|
|
|
|
return $response;
|
|
}
|
|
}
|