Operation processes on invoices
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\ChangeStatus;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class ChangeStatusRequest {
|
||||
public Invoice $invoice;
|
||||
public string $status;
|
||||
public ?string $comment;
|
||||
|
||||
public function __construct(Invoice $invoice, string $status, ?string $comment = null) {
|
||||
$this->invoice = $invoice;
|
||||
$this->status = $status;
|
||||
$this->comment = $comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\ChangeStatus;
|
||||
|
||||
class ChangeStatusResponse {
|
||||
public bool $success;
|
||||
|
||||
function __construct() {
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class CreateInvoiceCommand {
|
||||
'travel_direction' => $this->request->travelRoute,
|
||||
'passengers' => $this->request->passengers,
|
||||
'transportation' => $this->request->transportations,
|
||||
'document_filename' => $this->request->receiptFile !== null ? $this->request->receiptFile->path : null,
|
||||
'document_filename' => $this->request->receiptFile !== null ? $this->request->receiptFile->fullPath : null,
|
||||
]);
|
||||
|
||||
if ($invoice !== null) {
|
||||
|
||||
@@ -59,6 +59,11 @@ class CreateInvoiceRequest {
|
||||
$this->totalAmount = $totalAmount;
|
||||
$this->isDonation = $isDonation;
|
||||
$this->userId = $userId;
|
||||
|
||||
if ($accountIban === 'undefined') {
|
||||
$this->accountIban = null;
|
||||
$this->accountOwner = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UpdateInvoice;
|
||||
|
||||
use App\Domains\Invoice\Actions\ChangeStatus\ChangeStatusCommand;
|
||||
use App\Domains\Invoice\Actions\ChangeStatus\ChangeStatusRequest;
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
|
||||
class UpdateInvoiceCommand {
|
||||
private UpdateInvoiceRequest $request;
|
||||
|
||||
public function __construct(UpdateInvoiceRequest $request) {
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function execute() : UpdateInvoiceResponse {
|
||||
$response = new UpdateInvoiceResponse();
|
||||
|
||||
$this->request->invoice->amount = $this->request->amount->getAmount();
|
||||
$this->request->invoice->cost_unit_id = $this->request->costUnit->id;
|
||||
$this->request->invoice->type = $this->request->invoiceType;
|
||||
$this->request->invoice->comment = $this->request->comment;
|
||||
|
||||
$this->request->invoice->save();
|
||||
|
||||
$request = new ChangeStatusRequest($this->request->invoice, InvoiceStatus::INVOICE_STATUS_APPROVED);
|
||||
$changeStatusCommand = new ChangeStatusCommand($request);
|
||||
$changeStatusCommand->execute();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UpdateInvoice;
|
||||
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Models\CostUnit;
|
||||
use App\Models\Invoice;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class UpdateInvoiceRequest {
|
||||
public string $comment;
|
||||
public string $invoiceType;
|
||||
public CostUnit $costUnit;
|
||||
public Invoice $invoice;
|
||||
public Amount $amount;
|
||||
|
||||
public function __construct(Invoice $invoice, string $comment, string $invoiceType, CostUnit $costUnit, Amount $amount) {
|
||||
$this->comment = $comment;
|
||||
$this->invoiceType = $invoiceType;
|
||||
$this->costUnit = $costUnit;
|
||||
$this->invoice = $invoice;
|
||||
$this->amount = $amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Invoice\Actions\UpdateInvoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class UpdateInvoiceResponse {
|
||||
public bool $success;
|
||||
public ?Invoice $invoice;
|
||||
|
||||
public function __construct() {
|
||||
$this->success = false;
|
||||
$this->invoice = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user