mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Sales\Http\Requests\Concerns;
|
|
|
|
use Illuminate\Validation\Validator;
|
|
|
|
trait ValidatesDocumentTaxPlaceholders
|
|
{
|
|
protected function validateDocumentTaxPlaceholders(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator): void {
|
|
$items = $this->input('items', []);
|
|
|
|
if (! is_array($items)) {
|
|
return;
|
|
}
|
|
|
|
foreach ($items as $itemIndex => $item) {
|
|
if (! is_array($item)) {
|
|
continue;
|
|
}
|
|
|
|
$taxes = $item['taxes'] ?? [];
|
|
|
|
if (! is_array($taxes)) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($taxes as $taxIndex => $tax) {
|
|
if (! is_array($tax) || ! empty($tax['tax_type_id'])) {
|
|
continue;
|
|
}
|
|
|
|
if ((float) ($tax['amount'] ?? 0) !== 0.0) {
|
|
$validator->errors()->add(
|
|
"items.{$itemIndex}.taxes.{$taxIndex}.amount",
|
|
'A tax amount requires a tax type.'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|