feat: add getForEdit method to RestockService for enhanced restock item retrieval and media handling
This commit is contained in:
parent
3535480266
commit
50ece97933
@ -61,6 +61,31 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
public function getForEdit(Restock $restock): array
|
||||
{
|
||||
$restock->load([
|
||||
'restockItems' => fn ($q) => $q
|
||||
->select(['id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal']),
|
||||
'restockItems.productVariant:id,name',
|
||||
]);
|
||||
|
||||
$media = $restock->getFirstMedia('photos');
|
||||
|
||||
return [
|
||||
'id' => $restock->id,
|
||||
'stock_type' => $restock->stock_type->value,
|
||||
'notes' => $restock->notes,
|
||||
'photo_key' => $media?->getCustomProperty('s3_key') ?? $media?->file_name,
|
||||
'photo_url' => $media ? $this->s3Service->getTemporaryUrl($media->getPath()) : null,
|
||||
'items' => $restock->restockItems->map(fn ($item) => [
|
||||
'id' => $item->id,
|
||||
'product_variant_id' => $item->product_variant_id,
|
||||
'quantity' => $item->quantity,
|
||||
'unit_price' => $item->unit_price,
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getItems(Restock $restock): \Illuminate\Support\Collection
|
||||
{
|
||||
return $restock->restockItems()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user