CaiWuXiTong/app/Business/InventoryWarehouseShortNames.php
chenxi 26556a9169 Add warehouse short names to inventory report
Restore warehouse name mapping ledger and inventory short-name column.
2026-09-28 16:33:38 +08:00

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;
}
}