You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.3 KiB
82 lines
2.3 KiB
<?php
|
|
|
|
namespace App\Livewire\Forms\Finance;
|
|
|
|
use App\Domains\Finance\DTOs\PaymentProcessing\IssueInvoiceDTO;
|
|
use App\Domains\Finance\Enums\InvoiceStatus;
|
|
use App\Domains\Finance\Enums\InvoiceType;
|
|
use App\UI\Support\Schemas\InputSchemaField;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Form;
|
|
|
|
class InvoiceForm extends Form
|
|
{
|
|
#[Validate('required|string|max:255', as: 'domains/finance/field.invoice.name')]
|
|
public string $name = '';
|
|
|
|
#[Validate('required', as: 'domains/finance/field.invoice.type')]
|
|
public ?InvoiceType $type = null;
|
|
|
|
#[Validate]
|
|
public array $detail = [];
|
|
|
|
#[Validate('required', as: 'domains/finance/field.invoice.type')]
|
|
public string $client_id = '';
|
|
|
|
#[Validate('required', as: 'domains/finance/field.invoice.type')]
|
|
public string $coa_id = '';
|
|
|
|
#[Validate('required', as: 'domains/finance/field.invoice.type')]
|
|
public int $amount = 0;
|
|
|
|
public function updatedDetail($val, $prop): void
|
|
{
|
|
$formSchema = $this->type->schema()->getSchema();
|
|
|
|
$this->resetValidation();
|
|
foreach ($formSchema as $key => $schema) {
|
|
/** @var InputSchemaField $schema */
|
|
$schema = $schema->schema->getSchema();
|
|
if ($schema->dependsOn == $prop) {
|
|
$this->detail[$key] = '';
|
|
}
|
|
}
|
|
$this->validateOnly($prop);
|
|
}
|
|
|
|
public function updatedType(): void
|
|
{
|
|
$this->reset('detail');
|
|
|
|
$schema = $this->type?->getSchema() ?? [];
|
|
foreach ($schema as $value) {
|
|
$this->detail[$value->key] = '';
|
|
}
|
|
|
|
$this->resetValidation();
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return $this->type?->schema()?->getValidationRules('detail');
|
|
}
|
|
|
|
public function validationAttributes(): array
|
|
{
|
|
return $this->type?->schema()?->getValidationAttributes('detail');
|
|
}
|
|
|
|
public function toDto(): IssueInvoiceDTO
|
|
{
|
|
return new IssueInvoiceDTO(
|
|
name: $this->name,
|
|
clientRefId: $this->client_id,
|
|
detail: $this->type->dtoTransform($this->detail),
|
|
type: $this->type,
|
|
status: InvoiceStatus::PENDING,
|
|
amount: $this->amount,
|
|
coaId: $this->coa_id,
|
|
clientId: $this->client_id,
|
|
);
|
|
}
|
|
}
|
|
|