Compare commits

..

No commits in common. "5c1f92e48b3fbb44bd7bc1ca106e5ae4a1b4acd7" and "709eb768733767eb0990dbc5323e8081f36a8064" have entirely different histories.

47 changed files with 152 additions and 393 deletions

View File

@ -2,7 +2,6 @@
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;
@ -25,13 +24,10 @@ 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, [
'search_id' => $tableQuery['search_id'],
]),
'filters' => $this->dataTableFilters($tableQuery),
]);
}
@ -50,11 +46,7 @@ public function store(PurchaseRequest $request): RedirectResponse
{
$this->purchaseService->create($request->validated(), $request->user());
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashCreated('Belanja');
} else {
$this->flashSuccess('Belanja berhasil diajukan dan menunggu verifikasi owner.');
}
$this->flashSuccess('Belanja berhasil diajukan dan menunggu verifikasi owner.');
return redirect()->route('admin.manage.purchases.index');
}
@ -72,11 +64,7 @@ public function update(PurchaseRequest $request, Purchase $purchase): RedirectRe
{
$this->purchaseService->update($purchase, $request->validated(), $request->user());
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashUpdated('Belanja');
} else {
$this->flashSuccess('Perubahan belanja berhasil diajukan dan menunggu verifikasi owner.');
}
$this->flashSuccess('Perubahan belanja berhasil diajukan dan menunggu verifikasi owner.');
return redirect()->route('admin.manage.purchases.index');
}
@ -85,11 +73,7 @@ public function destroy(Request $request, Purchase $purchase): RedirectResponse
{
$this->purchaseService->delete($purchase, $request->user());
if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) {
$this->flashDeleted('Belanja');
} else {
$this->flashSuccess('Penghapusan belanja berhasil diajukan dan menunggu verifikasi owner.');
}
$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' => 'Transfer stok ecer berhasil dilakukan.',
'message' => 'Pengajuan transfer stok ecer berhasil dikirim dan menunggu verifikasi owner.',
]);
}
}

View File

@ -2,7 +2,6 @@
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;
@ -41,11 +40,7 @@ public function verify(StockVerifyRequest $request, Cutting $cutting): RedirectR
$request->validated('result_prices'),
);
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.');
}
$this->flashSuccess('Verifikasi berhasil diajukan. Menunggu persetujuan owner.');
return redirect()->route('admin.manage.stocks.index');
}

View File

@ -30,7 +30,6 @@ 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();
@ -42,7 +41,6 @@ public function index(Request $request): Response
'is_active' => $isActive,
'category_id' => $categoryId,
'stock_status' => $stockStatus,
'search_id' => $tableQuery['search_id'],
]),
]);
}

View File

@ -29,7 +29,6 @@ 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();
@ -40,7 +39,6 @@ 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

@ -1,68 +0,0 @@
<?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)->withTrashed();
return $this->belongsTo(Employee::class);
}
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')->withTrashed();
return $this->belongsTo(User::class, 'created_by_id');
}
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')->withTrashed();
return $this->belongsTo(User::class, 'created_by_id');
}
public function materials(): HasMany
@ -130,6 +130,6 @@ public function results(): HasMany
public function submittedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'submitted_by_id')->withTrashed();
return $this->belongsTo(User::class, 'submitted_by_id');
}
}

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)->withTrashed();
return $this->belongsTo(Cutting::class);
}
public function rawMaterialPrice(): BelongsTo
{
return $this->belongsTo(RawMaterialPrice::class)->withTrashed();
return $this->belongsTo(RawMaterialPrice::class);
}
public function combination(): BelongsTo
{
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id')->withTrashed();
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id');
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
return $this->belongsTo(User::class);
}
}

View File

@ -24,12 +24,12 @@ protected function casts(): array
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class)->withTrashed();
return $this->belongsTo(Cutting::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
return $this->belongsTo(User::class);
}
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)->withTrashed();
return $this->belongsTo(Cutting::class);
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class)->withTrashed();
return $this->belongsTo(ProductVariant::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
return $this->belongsTo(User::class);
}
}

View File

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

View File

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

View File

@ -201,7 +201,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class)->withTrashed();
return $this->belongsTo(Employee::class);
}
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')->withTrashed();
return $this->belongsTo(User::class, 'paid_by_id');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -163,7 +163,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class)->withTrashed();
return $this->belongsTo(Employee::class);
}
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')->withTrashed();
return $this->belongsTo(User::class, 'created_by_id');
}
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')->withTrashed();
return $this->belongsTo(User::class, 'closed_by_id');
}
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')->withTrashed();
return $this->belongsTo(ProductVariant::class, 'variant_id');
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -520,23 +520,56 @@ private function requestTitle(OwnerVerificationRequest $request): string
private function requestSearchTerm(OwnerVerificationRequest $request): ?string
{
if ($request->subject_type === MarketplaceSettings::class) {
return null;
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 === 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_id'])) {
return (string) $newData['product_id'];
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 ($request->subject_id !== null) {
return (string) $request->subject_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'];
}
}
}
return null;
@ -552,7 +585,7 @@ private function notifyRequestSubmitter(
}
$searchTerm = $this->requestSearchTerm($request);
$routeParams = $searchTerm !== null ? ['search_id' => $searchTerm] : [];
$routeParams = $searchTerm !== null ? ['search' => $searchTerm] : [];
$url = match ($request->subject_type) {
Product::class, ProductVariant::class => route('admin.master.products.index', $routeParams),

View File

@ -43,10 +43,7 @@ public function paginateForIndex(array $tableQuery): LengthAwarePaginator
'items.rawMaterialPrice.rawMaterial:id,name,unit',
'media',
])
->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 {
->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
$search = $tableQuery['search'];
$query->where(function (Builder $query) use ($search): void {
$query->where('notes', 'like', "%{$search}%")
@ -235,7 +232,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_id' => $rawMaterial->id]),
route('admin.master.raw_materials.index', ['search' => $rawMaterial->name]),
);
return [
@ -431,8 +428,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_id' => $purchase->id]),
(string) $purchase->id,
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
);
}
@ -483,8 +480,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_id' => $purchase->id]),
(string) $purchase->id,
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
);
}
@ -527,8 +524,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_id' => $purchase->id]),
(string) $purchase->id,
route('admin.manage.purchases.index', ['search' => $purchase->supplier->name]),
$purchase->supplier->name,
);
}
@ -688,7 +685,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_id' => $search]);
$ownerUrl = route('admin.manage.purchases.index', ['search' => $search]);
}
$this->pushNotificationService->sendToRoles(

View File

@ -33,11 +33,13 @@ 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_id' => $variant->product_id]),
route('admin.master.products.index', ['search' => $productName]),
);
}

View File

@ -3,7 +3,6 @@
namespace App\Services\Manage;
use App\Enums\CuttingStatus;
use App\Enums\Permission;
use App\Models\Cutting;
use App\Models\CuttingMaterial;
use App\Models\CuttingResult;
@ -86,10 +85,8 @@ public function submitVerification(
]);
}
$isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value);
try {
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices, $isOwner): void {
DB::transaction(function () use ($cutting, $user, $verificationNote, $results, $resultPrices): void {
$cutting->load(['materials.rawMaterialPrice', 'results']);
if ($results !== null) {
@ -114,15 +111,7 @@ public function submitVerification(
}
$cutting->submitted_by_id = $user->id;
if ($isOwner) {
$this->applyProductStockOnVerify($cutting);
$this->applyResultPricesToProducts($cutting);
$cutting->status = CuttingStatus::VERIFIED;
} else {
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
}
$cutting->status = CuttingStatus::PENDING_VERIFICATION;
$cutting->save();
});
} catch (ValidationException $e) {
@ -139,26 +128,14 @@ public function submitVerification(
$description = $cutting->description ?? '-';
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->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,10 +43,7 @@ public function paginateForIndex(array $tableQuery, string $isActive, string $ca
$query->where('name', 'like', "%{$tableQuery['search']}%");
}),
])
->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 {
->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void {
$search = $tableQuery['search'];
$query->whereHas('variants', fn (Builder $query) => $query->where('name', 'like', "%{$search}%"));
})
@ -121,8 +118,8 @@ public function create(array $validated, User $user): void
{
$isOwner = $user->can(Permission::OWNER_VERIFICATIONS_VERIFY->value);
$product = $this->runInTransaction(
function () use ($validated, $user, $isOwner): Product {
$this->runInTransaction(
function () use ($validated, $user, $isOwner): void {
$product = Product::create([
'name' => $validated['name'],
'description' => $validated['description'] ?? null,
@ -163,8 +160,6 @@ function () use ($validated, $user, $isOwner): Product {
],
]);
}
return $product;
},
'Gagal membuat produk',
);
@ -178,8 +173,8 @@ function () use ($validated, $user, $isOwner): Product {
$user,
'Tambah Produk',
"Pengajuan tambah produk '{$validated['name']}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
route('admin.master.products.index', ['search' => $validated['name']]),
$validated['name'],
);
}
}
@ -291,16 +286,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_id' => $product->id]),
(string) $product->id,
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
);
} else {
$this->notifyForPendingRequest(
$user,
'Ubah Produk',
"Pengajuan ubah produk '{$product->name}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
);
}
}
@ -339,8 +334,8 @@ function () use ($product, $user): void {
$user,
'Hapus Produk',
"Pengajuan hapus produk '{$product->name}' menunggu verifikasi owner.",
route('admin.master.products.index', ['search_id' => $product->id]),
(string) $product->id,
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
);
}
@ -388,8 +383,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_id' => $product->id]),
(string) $product->id,
route('admin.master.products.index', ['search' => $product->name]),
$product->name,
);
}
@ -589,7 +584,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_id' => $search]);
$ownerUrl = route('admin.master.products.index', ['search' => $search]);
}
$this->pushNotificationService->sendToRoles(

View File

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

View File

@ -23,8 +23,7 @@
<link rel="icon"
href="{{ $page['props']['favicon_url'] ?? ($page['props']['logo_url'] ?? asset('assets/logo.png')) }}"
sizes="any">
<link rel="apple-touch-icon" href="{{ $page['props']['logo_url'] ?? asset('assets/logo.png') }}">
<link rel="manifest" href="/pwa-manifest.json">
<link rel="manifest" href="/build/manifest.webmanifest">
<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,11 +38,9 @@
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,23 +400,6 @@ 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,52 +313,4 @@ 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,28 +163,6 @@ 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,25 +132,6 @@ 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);
@ -160,44 +141,6 @@ 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 ───────────────────────────────────────────────