-
-
-
- {{ rowNumber(index) }}
-
-
-
-
- {{ material.name }}
-
-
- {{ material.unit_label }}
-
-
-
- {{ material.pending_request_submitted_by_name }} mengajukan {{ material.pending_request_action_label?.toLowerCase() }} bahan baku ini —
-
-
-
-
- Total stok
- {{ material.total_stock_formatted }}
-
-
-
- Total harga
- {{ material.total_inventory_value_formatted }}
-
-
+
+
+
+
+ {{ rowNumber(index) }}
+
+
+
+
+ {{ material.name }}
+
+
+ {{ material.unit_label }}
+
+
+
+ {{ material.pending_request_submitted_by_name }} mengajukan {{
+ material.pending_request_action_label?.toLowerCase() }} bahan baku ini —
+
+
+
+
+ Total stok
+ {{ material.total_stock_formatted }}
+
+
+
+ Total harga
+ {{ material.total_inventory_value_formatted }}
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+ #
+ Varian
+ Foto
+ Stok
+ Harga per Satuan
+ Aksi
+
+
+
+
+
+ Belum ada varian
+
+
+
+
+ {{ priceIndex + 1 }}
+
+
+ {{ price.variant }}
+
+
+
+
+
+ {{ price.stock_formatted }}
+
+
+ {{ price.price_formatted }}
+
+
+
+
+
+
+
-
-
-
-
- #
- Varian
- Foto
- Stok
- Harga per Satuan
-
-
-
-
-
- Belum ada varian
-
-
-
-
- {{ priceIndex + 1 }}
-
-
- {{ price.variant }}
-
-
-
-
-
- {{ price.stock_formatted }}
-
-
- {{ price.price_formatted }}
-
-
-
-
-
@@ -170,5 +191,12 @@ function openVerificationDetail(requestId: number | undefined) {
+
+
+
diff --git a/routes/web.php b/routes/web.php
index 926da91..528f499 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -176,6 +176,7 @@
])
->name('destroy');
+ Route::get('{rawMaterial}', [RawMaterialController::class, 'show'])->name('show');
Route::get('/', [RawMaterialController::class, 'index'])->name('index');
});
diff --git a/tests/Feature/Admin/Master/RawMaterialTest.php b/tests/Feature/Admin/Master/RawMaterialTest.php
index bd8aac6..479f63f 100644
--- a/tests/Feature/Admin/Master/RawMaterialTest.php
+++ b/tests/Feature/Admin/Master/RawMaterialTest.php
@@ -738,8 +738,8 @@ function createRawMaterialVerifierUser(): User
RawMaterialPrice::factory()->create(['raw_material_id' => $rawMaterial->id, 'stock' => 10.5]);
RawMaterialPrice::factory()->create(['raw_material_id' => $rawMaterial->id, 'stock' => 5.25]);
- expect($rawMaterial->fresh()->total_stock_formatted)->toContain('15,75');
- expect($rawMaterial->fresh()->total_stock_formatted)->toContain('m');
+ expect($rawMaterial->fresh(['prices'])->total_stock_formatted)->toContain('15,75');
+ expect($rawMaterial->fresh(['prices'])->total_stock_formatted)->toContain('m');
});
});
@@ -907,3 +907,56 @@ function createRawMaterialVerifierUser(): User
expect($price->fresh()->variant)->toBe($originalVariant);
});
});
+
+// ─── Show JSON ────────────────────────────────────────────
+
+describe('Raw Material Show JSON', function () {
+ test('authenticated user with permission can get raw material details in JSON', function () {
+ $user = createRawMaterialUserWithPermission(PermissionEnum::RAW_MATERIALS_VIEW);
+
+ $rawMaterial = createRawMaterialWithPrices();
+
+ $response = $this->actingAs($user)
+ ->get(route('admin.master.raw_materials.show', $rawMaterial))
+ ->assertOk();
+
+ $response->assertJsonStructure([
+ 'id',
+ 'name',
+ 'unit',
+ 'prices' => [
+ '*' => [
+ 'id',
+ 'variant',
+ 'price',
+ 'price_formatted',
+ 'price_input',
+ 'stock_formatted',
+ 'stock_input',
+ 'images',
+ ],
+ ],
+ ]);
+
+ $data = $response->json();
+ expect($data['id'])->toBe($rawMaterial->id);
+ expect($data['prices'])->toHaveCount(2);
+ });
+
+ test('guest cannot get raw material details in JSON', function () {
+ $rawMaterial = createRawMaterialWithPrices();
+
+ $this->get(route('admin.master.raw_materials.show', $rawMaterial))
+ ->assertRedirect(route('login'));
+ });
+
+ test('user without view permission cannot get raw material details in JSON', function () {
+ $user = User::factory()->create();
+
+ $rawMaterial = createRawMaterialWithPrices();
+
+ $this->actingAs($user)
+ ->get(route('admin.master.raw_materials.show', $rawMaterial))
+ ->assertForbidden();
+ });
+});