36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Business;
|
|
|
|
use App\Models\Business\InventoryWarehouseNameMapping;
|
|
|
|
class InventoryWarehouseShortNames
|
|
{
|
|
/** @return array<string,string> */
|
|
public function forCompany(int $companyId): array
|
|
{
|
|
return InventoryWarehouseNameMapping::allCompanies()
|
|
->companyId($companyId)
|
|
->get(['warehouse_provider', 'warehouse', 'warehouse_short_name'])
|
|
->mapWithKeys(static fn (InventoryWarehouseNameMapping $mapping): array => [
|
|
self::key($mapping->warehouse_provider, $mapping->warehouse) => $mapping->warehouse_short_name,
|
|
])->all();
|
|
}
|
|
|
|
/** @param array<string,string> $names */
|
|
public function fill(object $row, array $names): object
|
|
{
|
|
$row->warehouse_short_name = $names[self::key(
|
|
(string) ($row->warehouse_provider ?? ''),
|
|
(string) ($row->warehouse ?? ''),
|
|
)] ?? '';
|
|
|
|
return $row;
|
|
}
|
|
|
|
private static function key(string $provider, string $warehouse): string
|
|
{
|
|
return $provider . "\0" . $warehouse;
|
|
}
|
|
}
|