Compare commits

...

5 Commits

47 changed files with 393 additions and 152 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin\Manage\Purchase;
use App\Enums\Permission;
use App\Http\Controllers\Concerns\FlashesEntityMessage;
use App\Http\Controllers\Concerns\ParsesDataTableQuery;
use App\Http\Controllers\Controller;
@ -24,10 +25,13 @@ public function __construct(
public function index(Request $request): Response
{
$tableQuery = $this->parseDataTableQuery($request);
$tableQuery['search_id'] = $request->string('search_id')->trim()->toString();
return Inertia::render('admin/manage/purchases/Index', [
'purchases' => $this->purchaseService->paginateForIndex($tableQuery),
'filters' => $this->dataTableFilters($tableQuery),
'filters' => $this->dataTableFilters($tableQuery, [
'search_id' => $tableQuery['search_id'],
]),
]);
}
@ -46,7 +50,11 @@ public function store(PurchaseRequest $request): RedirectResponse
{
$this->purchaseService->create($request->validated(), $request->user());
$this->flashSuccess('Belanja berhasil diajukan dan menunggu verifikasi owner.');
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashCreated('Belanja');
} else {
$this->flashSuccess('Belanja berhasil diajukan dan menunggu verifikasi owner.');
}
return redirect()->route('admin.manage.purchases.index');
}
@ -64,7 +72,11 @@ public function update(PurchaseRequest $request, Purchase $purchase): RedirectRe
{
$this->purchaseService->update($purchase, $request->validated(), $request->user());
$this->flashSuccess('Perubahan belanja berhasil diajukan dan menunggu verifikasi owner.');
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashUpdated('Belanja');
} else {
$this->flashSuccess('Perubahan belanja berhasil diajukan dan menunggu verifikasi owner.');
}
return redirect()->route('admin.manage.purchases.index');
}
@ -73,7 +85,11 @@ public function destroy(Request $request, Purchase $purchase): RedirectResponse
{
$this->purchaseService->delete($purchase, $request->user());
$this->flashSuccess('Penghapusan belanja berhasil diajukan dan menunggu verifikasi owner.');
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashDeleted('Belanja');
} else {
$this->flashSuccess('Penghapusan belanja berhasil diajukan dan menunggu verifikasi owner.');
}
return redirect()->route('admin.manage.purchases.index');
}

View File

@ -26,7 +26,7 @@ public function transfer(RetailStockTransferRequest $request): JsonResponse
return response()->json([
'success' => true,
'message' => 'Pengajuan transfer stok ecer berhasil dikirim dan menunggu verifikasi owner.',
'message' => 'Transfer stok ecer berhasil dilakukan.',
]);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin\Manage\Stock;
use App\Enums\Permission;
use App\Http\Controllers\Concerns\FlashesEntityMessage;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Manage\StockVerifyRequest;
@ -40,7 +41,11 @@ public function verify(StockVerifyRequest $request, Cutting $cutting): RedirectR
$request->validated('result_prices'),
);
$this->flashSuccess('Verifikasi berhasil diajukan. Menunggu persetujuan owner.');
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashSuccess('Verifikasi berhasil disimpan. Stok produk telah ditambahkan ke toko.');
} else {
$this->flashSuccess('Verifikasi berhasil diajukan. Menunggu persetujuan owner.');
}
return redirect()->route('admin.manage.stocks.index');
}

View File

@ -30,6 +30,7 @@ public function __construct(
public function index(Request $request): Response
{
$tableQuery = $this->parseDataTableQuery($request);
$tableQuery['search_id'] = $request->string('search_id')->trim()->toString();
$isActive = $request->string('is_active')->toString();
$categoryId = $request->string('category_id')->toString();
$stockStatus = $request->string('stock_status')->toString();
@ -41,6 +42,7 @@ public function index(Request $request): Response
'is_active' => $isActive,
'category_id' => $categoryId,
'stock_status' => $stockStatus,
'search_id' => $tableQuery['search_id'],
]),
]);
}

View File

@ -29,6 +29,7 @@ public function __construct(
public function index(Request $request): Response
{
$tableQuery = $this->parseDataTableQuery($request);
$tableQuery['search_id'] = $request->string('search_id')->trim()->toString();
$isActive = $request->string('is_active')->toString();
$stockStatus = $request->string('stock_status')->toString();
$rawMaterialId = $request->string('raw_material_id')->toString();
@ -39,6 +40,7 @@ public function index(Request $request): Response
'is_active' => $isActive,
'stock_status' => $stockStatus,
'raw_material_id' => $rawMaterialId,
'search_id' => $tableQuery['search_id'],
]),
'rawMaterialsList' => RawMaterial::query()->orderBy('name')->get(['id', 'name'])->map(fn ($r) => ['value' => (string) $r->id, 'label' => $r->name])->all(),
]);

View File

@ -0,0 +1,68 @@
<?php
namespace App\Http\Controllers;
use App\Services\System\Setting\SystemService;
use Illuminate\Http\JsonResponse;
class PwaManifestController extends Controller
{
public function show(SystemService $systemService): JsonResponse
{
$systemData = $systemService->systemData();
$appName = $systemData['app_name'] ?? config('app.name', 'DST Collection');
$logoUrl = $systemData['logo_url'] ?? asset('assets/logo.png');
// Determine mime type from logoUrl extension
$mimeType = 'image/png';
$lowerLogoUrl = strtolower($logoUrl);
if (str_contains($lowerLogoUrl, '.svg')) {
$mimeType = 'image/svg+xml';
} elseif (str_contains($lowerLogoUrl, '.jpg') || str_contains($lowerLogoUrl, '.jpeg')) {
$mimeType = 'image/jpeg';
} elseif (str_contains($lowerLogoUrl, '.webp')) {
$mimeType = 'image/webp';
}
$manifest = [
'name' => $appName,
'short_name' => $appName,
'description' => "{$appName} - Progressive Web App",
'theme_color' => '#171717',
'background_color' => '#ffffff',
'display' => 'standalone',
'orientation' => 'portrait',
'scope' => '/',
'start_url' => '/',
'id' => '/',
'icons' => [
[
'src' => $logoUrl,
'sizes' => '64x64',
'type' => $mimeType,
],
[
'src' => $logoUrl,
'sizes' => '192x192',
'type' => $mimeType,
],
[
'src' => $logoUrl,
'sizes' => '512x512',
'type' => $mimeType,
'purpose' => 'any',
],
[
'src' => $logoUrl,
'sizes' => '512x512',
'type' => $mimeType,
'purpose' => 'maskable',
],
],
];
return response()->json($manifest)
->header('Content-Type', 'application/manifest+json')
->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
}

View File

@ -130,7 +130,7 @@ public function registerMediaCollections(): void
// 5. Relation
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function payrollAdjustments(): HasMany

View File

@ -191,7 +191,7 @@ public function cashAccount(): BelongsTo
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function order(): HasOne

View File

@ -105,7 +105,7 @@ public function ensureEditable(): void
// 6. Relation
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function materials(): HasMany
@ -130,6 +130,6 @@ public function results(): HasMany
public function submittedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'submitted_by_id');
return $this->belongsTo(User::class, 'submitted_by_id')->withTrashed();
}
}

View File

@ -81,21 +81,21 @@ private function formatQuantityInput(float|string|null $value): string
// 5. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function rawMaterialPrice(): BelongsTo
{
return $this->belongsTo(RawMaterialPrice::class);
return $this->belongsTo(RawMaterialPrice::class)->withTrashed();
}
public function combination(): BelongsTo
{
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id');
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id')->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -24,12 +24,12 @@ protected function casts(): array
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
public function materials(): HasMany

View File

@ -28,16 +28,16 @@ protected function casts(): array
// 3. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -53,11 +53,11 @@ public function typeLabel(): Attribute
// 4. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
}

View File

@ -118,6 +118,6 @@ public function payrolls(): HasMany
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -201,7 +201,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function paidBy(): BelongsTo

View File

@ -56,6 +56,6 @@ public function employeeAdvance(): BelongsTo
public function paidBy(): BelongsTo
{
return $this->belongsTo(User::class, 'paid_by_id');
return $this->belongsTo(User::class, 'paid_by_id')->withTrashed();
}
}

View File

@ -64,11 +64,11 @@ public function registerMediaCollections(): void
// 5. Relation
public function cashTransaction(): BelongsTo
{
return $this->belongsTo(CashTransaction::class);
return $this->belongsTo(CashTransaction::class)->withTrashed();
}
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
}

View File

@ -158,7 +158,7 @@ public static function canSubmit(User $user): bool
// 6. Relation
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function verifiedBy(): BelongsTo

View File

@ -45,6 +45,6 @@ public function markAsRead(): void
// 4. Relation
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -289,17 +289,17 @@ public function registerMediaCollections(): void
// 6. Relation
public function cashTransaction(): BelongsTo
{
return $this->belongsTo(CashTransaction::class);
return $this->belongsTo(CashTransaction::class)->withTrashed();
}
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
return $this->belongsTo(Customer::class)->withTrashed();
}
public function items(): HasMany
@ -309,6 +309,6 @@ public function items(): HasMany
public function marketing(): BelongsTo
{
return $this->belongsTo(User::class, 'marketing_id');
return $this->belongsTo(User::class, 'marketing_id')->withTrashed();
}
}

View File

@ -67,16 +67,16 @@ public function unitPriceFormatted(): Attribute
// 4. Relation
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
return $this->belongsTo(Order::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -184,11 +184,11 @@ public function subject(): MorphTo
public function submittedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'submitted_by_id');
return $this->belongsTo(User::class, 'submitted_by_id')->withTrashed();
}
public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by_id');
return $this->belongsTo(User::class, 'verified_by_id')->withTrashed();
}
}

View File

@ -163,7 +163,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function paidBy(): BelongsTo

View File

@ -83,7 +83,7 @@ public function attendance(): BelongsTo
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function payroll(): BelongsTo

View File

@ -77,7 +77,7 @@ public function isOpen(): bool
// 6. Relation
public function closedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'closed_by_id');
return $this->belongsTo(User::class, 'closed_by_id')->withTrashed();
}
public function payrolls(): HasMany

View File

@ -44,6 +44,6 @@ public function priceInput(): Attribute
// 4. Relation
public function variant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class, 'variant_id');
return $this->belongsTo(ProductVariant::class, 'variant_id')->withTrashed();
}
}

View File

@ -94,6 +94,6 @@ public function prices(): HasMany
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
return $this->belongsTo(Product::class)->withTrashed();
}
}

View File

@ -114,6 +114,6 @@ public function pendingOwnerVerificationRequest(): MorphOne
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class);
return $this->belongsTo(Supplier::class)->withTrashed();
}
}

View File

@ -80,16 +80,16 @@ public function unitPriceFormatted(): Attribute
// 4. Relation
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
return $this->belongsTo(Purchase::class)->withTrashed();
}
public function rawMaterialPrice(): BelongsTo
{
return $this->belongsTo(RawMaterialPrice::class);
return $this->belongsTo(RawMaterialPrice::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -89,6 +89,6 @@ public function purchaseItems(): HasMany
public function rawMaterial(): BelongsTo
{
return $this->belongsTo(RawMaterial::class);
return $this->belongsTo(RawMaterial::class)->withTrashed();
}
}

View File

@ -23,6 +23,6 @@ public function rejectable(): MorphTo
public function rejectedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'rejected_by_id');
return $this->belongsTo(User::class, 'rejected_by_id')->withTrashed();
}
}

View File

@ -29,11 +29,11 @@ protected function casts(): array
// 2. Relation
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -89,7 +89,7 @@ public function statusLabel(): Attribute
// 5. Relation
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function items(): HasMany
@ -99,6 +99,6 @@ public function items(): HasMany
public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by_id');
return $this->belongsTo(User::class, 'verified_by_id')->withTrashed();
}
}

View File

@ -43,11 +43,11 @@ public function getVariantNameAttribute(): string
// 3. Relation
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function stokOpname(): BelongsTo
{
return $this->belongsTo(StokOpname::class);
return $this->belongsTo(StokOpname::class)->withTrashed();
}
}

View File

@ -87,6 +87,6 @@ public function registerMediaCollections(): void
// 5. Relation
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -520,56 +520,23 @@ private function requestTitle(OwnerVerificationRequest $request): string
private function requestSearchTerm(OwnerVerificationRequest $request): ?string
{
if ($request->subject_type === Product::class) {
if ($request->subject instanceof Product) {
return $request->subject->name;
}
$payload = is_array($request->payload) ? $request->payload : [];
foreach (['new', 'old'] as $key) {
$section = $payload[$key] ?? null;
if (is_array($section) && isset($section['name'])) {
return (string) $section['name'];
}
}
if ($request->subject_type === MarketplaceSettings::class) {
return null;
}
if ($request->subject_type === ProductVariant::class) {
if ($request->subject instanceof ProductVariant) {
return (string) $request->subject->product_id;
}
$payload = is_array($request->payload) ? $request->payload : [];
$newData = $payload['new'] ?? [];
if (isset($newData['product_name']) && $newData['product_name'] !== '-') {
return $newData['product_name'];
}
if ($request->subject instanceof ProductVariant) {
return $request->subject->product?->name ?? $request->subject->name;
if (isset($newData['product_id'])) {
return (string) $newData['product_id'];
}
}
if ($request->subject_type === RawMaterial::class) {
if ($request->subject instanceof RawMaterial) {
return $request->subject->name;
}
$payload = is_array($request->payload) ? $request->payload : [];
foreach (['new', 'old'] as $key) {
$section = $payload[$key] ?? null;
if (is_array($section) && isset($section['name'])) {
return (string) $section['name'];
}
}
}
if ($request->subject_type === Purchase::class) {
if ($request->subject instanceof Purchase) {
$request->subject->loadMissing('supplier');
return $request->subject->supplier?->name;
}
$payload = is_array($request->payload) ? $request->payload : [];
foreach (['new', 'old'] as $key) {
$section = $payload[$key] ?? null;
if (is_array($section) && isset($section['supplier_name'])) {
return (string) $section['supplier_name'];
}
}
if ($request->subject_id !== null) {
return (string) $request->subject_id;
}
return null;
@ -585,7 +552,7 @@ private function notifyRequestSubmitter(
}
$searchTerm = $this->requestSearchTerm($request);
$routeParams = $searchTerm !== null ? ['search' => $searchTerm] : [];
$routeParams = $searchTerm !== null ? ['search_id' => $searchTerm] : [];
$url = match ($request->subject_type) {
Product::class, ProductVariant::class => route('admin.master.products.index', $routeParams),

View File

@ -43,7 +43,10 @@ public function paginateForIndex(array $tableQuery): LengthAwarePaginator
'items.rawMaterialPrice.rawMaterial:id,name,unit',
'media',
])
->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
->when(($tableQuery['search_id'] ?? '') !== '', function (Builder $query) use ($tableQuery): void {
$query->where('purchases.id', $tableQuery['search_id']);
})
->when(($tableQuery['search_id'] ?? '') === '' && $tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
$search = $tableQuery['search'];
$query->where(function (Builder $query) use ($search): void {
$query->where('notes', 'like', "%{$search}%")
@ -232,7 +235,7 @@ public function createVariantAndDraft(array $validated, User $user): array
'🆕 Varian Baru Ditambahkan',
"{$user->name} menambahkan varian \"{$price->variant}\" ke bahan baku \"{$rawMaterial->name}\".",
['owner', 'developer', 'direktur'],
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
);
return [
@ -428,8 +431,8 @@ function () use ($validated, $user, $isOwner): Purchase {
$user,
'Tambah Belanja',
"Pengajuan belanja dari supplier {$purchase->supplier->name} senilai {$purchase->total_formatted} menunggu verifikasi owner.",
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
route('admin.manage.purchases.index', ['search_id' => $purchase->id]),
(string) $purchase->id,
);
}
@ -480,8 +483,8 @@ function () use ($purchase, $validated, $user, $isOwner): void {
$user,
'Ubah Belanja',
"Pengajuan ubah belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.",
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
route('admin.manage.purchases.index', ['search_id' => $purchase->id]),
(string) $purchase->id,
);
}
@ -524,8 +527,8 @@ function () use ($purchase, $user): void {
$user,
'Hapus Belanja',
"Pengajuan hapus belanja dari supplier {$purchase->supplier->name} menunggu verifikasi owner.",
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
route('admin.manage.purchases.index', ['search_id' => $purchase->id]),
(string) $purchase->id,
);
}
@ -685,7 +688,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
{
$ownerUrl = route('admin.manage.purchases.index');
if ($search !== null) {
$ownerUrl = route('admin.manage.purchases.index', ['search' => $search]);
$ownerUrl = route('admin.manage.purchases.index', ['search_id' => $search]);
}
$this->pushNotificationService->sendToRoles(

View File

@ -33,13 +33,11 @@ public function transfer(int $variantId, int $quantity, User $user, ?string $not
$this->executeTransfer($variant, $quantity, $user, $notes);
$productName = $variant->product?->name ?? $variant->name;
$this->pushNotificationService->sendToRoles(
'📦 Perubahan Stok Ecer',
"Perubahan {$quantity} pcs stok ecer untuk varian '{$variant->name}' telah diterapkan.",
['owner', 'developer', 'direktur'],
route('admin.master.products.index', ['search' => $productName]),
route('admin.master.products.index', ['search_id' => $variant->product_id]),
);
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Manage;
use App\Enums\CuttingStatus;
use App\Enums\Permission;
use App\Models\Cutting;
use App\Models\CuttingMaterial;
use App\Models\CuttingResult;
@ -85,8 +86,10 @@ public function submitVerification(
]);
}
$isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value);
try {
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices): void {
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices, $isOwner): void {
$cutting->load(['materials.rawMaterialPrice', 'results']);
if ($results !== null) {
@ -111,7 +114,15 @@ public function submitVerification(
}
$cutting->submitted_by_id = $user->id;
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
if ($isOwner) {
$this->applyProductStockOnVerify($cutting);
$this->applyResultPricesToProducts($cutting);
$cutting->status = CuttingStatus::VERIFIED;
} else {
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
}
$cutting->save();
});
} catch (ValidationException $e) {
@ -128,14 +139,26 @@ public function submitVerification(
$description = $cutting->description ?? '-';
$this->pushNotificationService->sendToRoles(
'📦 Verifikasi Stok Menunggu Persetujuan',
"Cutting dengan deskripsi '{$description}' telah diajukan verifikasi dan menunggu persetujuan owner.",
['owner', 'developer', 'direktur'],
route('admin.manage.stocks.index'),
);
if ($isOwner) {
$this->pushNotificationService->sendToRoles(
'📦 Stok Cutting Diverifikasi',
"Cutting dengan deskripsi '{$description}' telah disetujui owner dan stok produk telah ditambahkan ke toko.",
['owner', 'developer', 'direktur'],
route('admin.manage.stocks.index'),
);
} else {
$this->pushNotificationService->sendToRoles(
'📦 Verifikasi Stok Menunggu Persetujuan',
"Cutting dengan deskripsi '{$description}' telah diajukan verifikasi dan menunggu persetujuan owner.",
['owner', 'developer', 'direktur'],
route('admin.manage.stocks.index'),
);
}
$this->cacheForgetByPattern('manage:stocks:*');
if ($isOwner) {
$this->cacheForgetByPattern('prices:*');
}
}
public function approveVerification(

View File

@ -43,7 +43,10 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $ca
$query->where('name', 'like', "%{$tableQuery['search']}%");
}),
])
->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
->when(($tableQuery['search_id'] ?? '') !== '', function (Builder $query) use ($tableQuery): void {
$query->where('products.id', $tableQuery['search_id']);
})
->when(($tableQuery['search_id'] ?? '') === '' && $tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
$search = $tableQuery['search'];
$query->whereHas('variants', fn (Builder $query) => $query->where('name', 'like', "%{$search}%"));
})
@ -118,8 +121,8 @@ public function create(array $validated, User $user): void
{
$isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value);
$this->runInTransaction(
function () use ($validated, $user, $isOwner): void {
$product = $this->runInTransaction(
function () use ($validated, $user, $isOwner): Product {
$product = Product::create([
'name' => $validated['name'],
'description' => $validated['description'] ?? null,
@ -160,6 +163,8 @@ function () use ($validated, $user, $isOwner): void {
],
]);
}
return $product;
},
'Gagal membuat produk',
);
@ -173,8 +178,8 @@ function () use ($validated, $user, $isOwner): void {
$user,
'Tambah Produk',
"Pengajuan tambah produk '{$validated['name']}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search' => $validated['name']]),
$validated['name'],
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
);
}
}
@ -286,16 +291,16 @@ function () use ($validated, $product, $user, $isOwner): void {
$user,
'Ubah Varian Produk',
"Pengajuan ubah varian '{$variantsStr}' pada produk '{$product->name}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
);
} else {
$this->notifyForPendingRequest(
$user,
'Ubah Produk',
"Pengajuan ubah produk '{$product->name}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
);
}
}
@ -334,8 +339,8 @@ function () use ($product, $user): void {
$user,
'Hapus Produk',
"Pengajuan hapus produk '{$product->name}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
);
}
@ -383,8 +388,8 @@ function () use ($product, $validated, $user): void {
$user,
'Ubah Status Produk',
"Pengajuan ubah status produk '{$product->name}' menjadi {$statusLabel} menunggu verifikasi owner.",
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
);
}
@ -584,7 +589,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
{
$ownerUrl = route('admin.master.products.index');
if ($search !== null) {
$ownerUrl = route('admin.master.products.index', ['search' => $search]);
$ownerUrl = route('admin.master.products.index', ['search_id' => $search]);
}
$this->pushNotificationService->sendToRoles(

View File

@ -42,7 +42,10 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
$query->where('variant', 'like', "%{$tableQuery['search']}%");
}),
])
->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
->when(($tableQuery['search_id'] ?? '') !== '', function (Builder $query) use ($tableQuery): void {
$query->where('raw_materials.id', $tableQuery['search_id']);
})
->when(($tableQuery['search_id'] ?? '') === '' && $tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
$search = $tableQuery['search'];
$query->whereHas('prices', fn (Builder $query) => $query->where('variant', 'like', "%{$search}%"));
})
@ -53,17 +56,17 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $st
})
->when($stockStatus === 'low_stock', function (Builder $query): void {
$minStock = [
RawMaterialUnit::YARD => 20,
RawMaterialUnit::METER => 10,
RawMaterialUnit::KILOGRAM => 5,
RawMaterialUnit::YARD->value => 20,
RawMaterialUnit::METER->value => 10,
RawMaterialUnit::KILOGRAM->value => 5,
];
$query->whereHas('prices', function (Builder $priceQuery) use ($minStock): void {
$priceQuery->where('stock', '>', 0)->where(function (Builder $priceQuery) use ($minStock): void {
foreach (RawMaterialUnit::cases() as $unit) {
$priceQuery->orWhere(function (Builder $priceQuery) use ($unit, $minStock): void {
$priceQuery->whereHas('rawMaterial', fn (Builder $rawMaterialQuery) => $rawMaterialQuery->where('unit', $unit))
->where('stock', '<', $minStock[$unit]);
$priceQuery->whereHas('rawMaterial', fn (Builder $rawMaterialQuery) => $rawMaterialQuery->where('unit', $unit->value))
->where('stock', '<', $minStock[$unit->value]);
});
}
});
@ -117,8 +120,8 @@ public function create(array $validated, User $user): void
{
$isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value);
$this->runInTransaction(
function () use ($validated, $user, $isOwner): void {
$rawMaterial = $this->runInTransaction(
function () use ($validated, $user, $isOwner): RawMaterial {
$rawMaterial = RawMaterial::create([
'name' => $validated['name'],
'unit' => $validated['unit'],
@ -142,6 +145,8 @@ function () use ($validated, $user, $isOwner): void {
],
]);
}
return $rawMaterial;
},
'Gagal membuat bahan baku',
);
@ -155,8 +160,8 @@ function () use ($validated, $user, $isOwner): void {
$user,
'Tambah Bahan Baku',
"Pengajuan tambah bahan baku '{$validated['name']}' menunggu verifikasi owner.",
route('admin.master.raw_materials.index', ['search' => $validated['name']]),
$validated['name'],
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
(string) $rawMaterial->id,
);
}
}
@ -239,16 +244,16 @@ function () use ($validated, $rawMaterial, $user, $isOwner): void {
$user,
'Ubah Varian Bahan Baku',
"Pengajuan ubah varian '{$variantsStr}' pada bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.",
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
$rawMaterial->name,
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
(string) $rawMaterial->id,
);
} else {
$this->notifyForPendingRequest(
$user,
'Ubah Bahan Baku',
"Pengajuan ubah bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.",
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
$rawMaterial->name,
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
(string) $rawMaterial->id,
);
}
}
@ -286,8 +291,8 @@ function () use ($rawMaterial, $user): void {
$user,
'Hapus Bahan Baku',
"Pengajuan hapus bahan baku '{$rawMaterial->name}' menunggu verifikasi owner.",
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
$rawMaterial->name,
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
(string) $rawMaterial->id,
);
}
@ -334,8 +339,8 @@ function () use ($rawMaterial, $validated, $user): void {
$user,
'Ubah Status Bahan Baku',
"Pengajuan ubah status bahan baku '{$rawMaterial->name}' menjadi {$statusLabel} menunggu verifikasi owner.",
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
$rawMaterial->name,
route('admin.master.raw_materials.index', ['search_id' => $rawMaterial->id]),
(string) $rawMaterial->id,
);
}
@ -383,7 +388,7 @@ private function notifyForPendingRequest(User $user, string $typeLabel, string $
{
$ownerUrl = route('admin.master.raw_materials.index');
if ($search !== null) {
$ownerUrl = route('admin.master.raw_materials.index', ['search' => $search]);
$ownerUrl = route('admin.master.raw_materials.index', ['search_id' => $search]);
}
$this->pushNotificationService->sendToRoles(

View File

@ -23,7 +23,8 @@
<link rel="icon"
href="{{ $page['props']['favicon_url'] ?? ($page['props']['logo_url'] ?? asset('assets/logo.png')) }}"
sizes="any">
<link rel="manifest" href="/build/manifest.webmanifest">
<link rel="apple-touch-icon" href="{{ $page['props']['logo_url'] ?? asset('assets/logo.png') }}">
<link rel="manifest" href="/pwa-manifest.json">
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600" rel="stylesheet" />

View File

@ -38,9 +38,11 @@
use App\Http\Controllers\Auth\LogoutController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\PushSubscriptionController;
use App\Http\Controllers\PwaManifestController;
use Illuminate\Support\Facades\Route;
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/pwa-manifest.json', [PwaManifestController::class, 'show'])->name('pwa.manifest');
Route::middleware('guest')->group(function () {
Route::get('/auth/login', [LoginController::class, 'index'])->name('login');

View File

@ -400,6 +400,23 @@ function getPurchaseItemsPayload(RawMaterialPrice $price, float $quantity = 2):
->get(route('admin.manage.purchases.index', ['search' => 'Kain']))
->assertOk();
});
test('index can search purchases by id', function () {
$user = createPurchaseUserWithPermission(PermissionEnum::PURCHASES_VIEW);
$supplier = Supplier::factory()->create(['name' => 'Supplier Kain']);
$purchase1 = Purchase::factory()->create(['supplier_id' => $supplier->id, 'created_by_id' => $user->id]);
$purchase2 = Purchase::factory()->create(['supplier_id' => $supplier->id, 'created_by_id' => $user->id]);
$response = $this->actingAs($user)
->get(route('admin.manage.purchases.index', ['search_id' => $purchase1->id]));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('purchases.data', 1)
->where('purchases.data.0.id', $purchase1->id)
);
});
});
// ─── Create ───────────────────────────────────────────────

View File

@ -313,4 +313,52 @@ function createCompletedCuttingSetup(): array
])
->assertForbidden();
});
test('owner can verify stock directly without pending verification', function () {
$user = createStockUserWithPermission(
PermissionEnum::STOCKS_VIEW,
PermissionEnum::CUTTINGS_VERIFY,
PermissionEnum::OWNER_VERIFICATIONS_VERIFY
);
$setup = createCompletedCuttingSetup();
$cutting = $setup['cutting'];
$payload = [
'verification_note' => 'Verified directly by owner',
'results' => [
[
'product_variant_id' => $setup['variant']->id,
'good' => 6,
'reject' => 1,
],
],
'result_prices' => [
[
'product_variant_id' => $setup['variant']->id,
'prices' => [
[
'type' => 'harga_modal',
'price' => 50000,
],
[
'type' => 'retail',
'price' => 75000,
],
],
],
],
];
$this->actingAs($user)
->post(route('admin.manage.stocks.verify', $cutting), $payload)
->assertRedirect(route('admin.manage.stocks.index'));
$cutting->refresh();
$this->assertEquals(CuttingStatus::VERIFIED, $cutting->status);
$setup['variant']->refresh();
// Base stock was 10. Added good stock is 6.
$this->assertEquals(16, $setup['variant']->stock);
});
});

View File

@ -163,6 +163,28 @@ function variantUpdateData(int $id, string $name = 'Updated Variant', int $stock
->assertOk();
});
test('index can search products by id', function () {
$user = createProductUserWithPermission(PermissionEnum::PRODUCTS_VIEW);
$category = Category::factory()->create();
$product1 = Product::factory()->create(['name' => 'Batik Modern']);
$product1->categories()->attach($category->id);
ProductVariant::factory()->create(['product_id' => $product1->id]);
$product2 = Product::factory()->create(['name' => 'Baju Sutra']);
$product2->categories()->attach($category->id);
ProductVariant::factory()->create(['product_id' => $product2->id]);
$response = $this->actingAs($user)
->get(route('admin.master.products.index', ['search_id' => $product1->id]));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('products.data', 1)
->where('products.data.0.id', $product1->id)
);
});
test('index can filter by active status', function () {
$user = createProductUserWithPermission(PermissionEnum::PRODUCTS_VIEW);

View File

@ -132,6 +132,25 @@ function createRawMaterialVerifierUser(): User
->assertOk();
});
test('index can search raw materials by id', function () {
$user = createRawMaterialUserWithPermission(PermissionEnum::RAW_MATERIALS_VIEW);
$rawMaterial1 = RawMaterial::factory()->create(['name' => 'Kain Batik']);
RawMaterialPrice::factory()->create(['raw_material_id' => $rawMaterial1->id]);
$rawMaterial2 = RawMaterial::factory()->create(['name' => 'Sutra Premium']);
RawMaterialPrice::factory()->create(['raw_material_id' => $rawMaterial2->id]);
$response = $this->actingAs($user)
->get(route('admin.master.raw_materials.index', ['search_id' => $rawMaterial1->id]));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('rawMaterials.data', 1)
->where('rawMaterials.data.0.id', $rawMaterial1->id)
);
});
test('index can filter by active status', function () {
$user = createRawMaterialUserWithPermission(PermissionEnum::RAW_MATERIALS_VIEW);
@ -141,6 +160,44 @@ function createRawMaterialVerifierUser(): User
->get(route('admin.master.raw_materials.index', ['is_active' => '1']))
->assertOk();
});
test('index can filter by stock status (out of stock)', function () {
$user = createRawMaterialUserWithPermission(PermissionEnum::RAW_MATERIALS_VIEW);
$inStock = RawMaterial::factory()->create();
RawMaterialPrice::factory()->create(['raw_material_id' => $inStock->id, 'stock' => 10]);
$outOfStock = RawMaterial::factory()->create();
RawMaterialPrice::factory()->create(['raw_material_id' => $outOfStock->id, 'stock' => 0]);
$response = $this->actingAs($user)
->get(route('admin.master.raw_materials.index', ['stock_status' => 'out_of_stock']));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('rawMaterials.data', 1)
->where('rawMaterials.data.0.id', $outOfStock->id)
);
});
test('index can filter by stock status (low stock)', function () {
$user = createRawMaterialUserWithPermission(PermissionEnum::RAW_MATERIALS_VIEW);
$yardNormal = RawMaterial::factory()->create(['unit' => RawMaterialUnit::YARD->value]);
RawMaterialPrice::factory()->create(['raw_material_id' => $yardNormal->id, 'stock' => 25]);
$yardLow = RawMaterial::factory()->create(['unit' => RawMaterialUnit::YARD->value]);
RawMaterialPrice::factory()->create(['raw_material_id' => $yardLow->id, 'stock' => 15]);
$response = $this->actingAs($user)
->get(route('admin.master.raw_materials.index', ['stock_status' => 'low_stock']));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->has('rawMaterials.data', 1)
->where('rawMaterials.data.0.id', $yardLow->id)
);
});
});
// ─── Create ───────────────────────────────────────────────