37 lines
977 B
PHP
37 lines
977 B
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Support;
|
|
|
|
use Illuminate\Database\Query\Builder;
|
|
|
|
final class DingInvoiceProcessScope
|
|
{
|
|
/** @return list<string> */
|
|
public static function documentTypes(): array
|
|
{
|
|
return array_values(array_unique(array_filter(array_map(
|
|
static fn (mixed $value): string => trim((string) $value),
|
|
(array) config('ding_invoice_data.document_types', []),
|
|
))));
|
|
}
|
|
|
|
public static function allows(?string $documentType): bool
|
|
{
|
|
return in_array(trim((string) $documentType), self::documentTypes(), true);
|
|
}
|
|
|
|
public static function apply(Builder $query, string $alias = ''): void
|
|
{
|
|
$column = $alias === '' ? 'document_type' : "{$alias}.document_type";
|
|
$documentTypes = self::documentTypes();
|
|
|
|
if ($documentTypes === []) {
|
|
$query->whereRaw('1 = 0');
|
|
|
|
return;
|
|
}
|
|
|
|
$query->whereIn($column, $documentTypes);
|
|
}
|
|
}
|