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.
101 lines
2.7 KiB
101 lines
2.7 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\Settings\SettingSchema;
|
|
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 SettingSchema $schema */
|
|
$schema = $schema->schema;
|
|
if ($schema->depends == $prop) {
|
|
$this->detail[$key] = '';
|
|
}
|
|
}
|
|
$this->validateOnly($prop);
|
|
}
|
|
|
|
public function updatedType(): void
|
|
{
|
|
$this->reset('detail');
|
|
|
|
$schema = $this->type?->schema()?->getSchema() ?? [];
|
|
foreach ($schema as $key => $value) {
|
|
$this->detail[$key] = '';
|
|
}
|
|
|
|
$this->resetValidation();
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$rules = [];
|
|
$detailSchema = $this->type
|
|
?->schema()
|
|
->getSchema() ?? [];
|
|
foreach ($detailSchema as $key => $schema) {
|
|
$rules = array_merge($rules, [
|
|
'detail.'.$key => $schema->schema->rules,
|
|
]);
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public function validationAttributes(): array
|
|
{
|
|
$attributes = [];
|
|
$detailSchema = $this->type
|
|
?->schema()
|
|
->getSchema() ?? [];
|
|
foreach ($detailSchema as $key => $schema) {
|
|
$attributes = array_merge($attributes, [
|
|
'detail.'.$key => $schema->schema->attributes['label'],
|
|
]);
|
|
}
|
|
|
|
return $attributes;
|
|
}
|
|
|
|
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,
|
|
clientId: $this->client_id
|
|
);
|
|
}
|
|
}
|
|
|