diff --git a/app/Enums/Role.php b/app/Enums/Role.php index abdba1f..3b79ac8 100644 --- a/app/Enums/Role.php +++ b/app/Enums/Role.php @@ -201,8 +201,6 @@ public function permissions(): array self::MARKETING => [ Permission::DASHBOARD_VIEW, - Permission::EMPLOYEES_VIEW, - Permission::ATTENDANCES_VIEW, Permission::ATTENDANCES_CREATE, @@ -212,28 +210,20 @@ public function permissions(): array Permission::LEAVE_REQUESTS_DELETE, Permission::CATEGORIES_VIEW, - Permission::CATEGORIES_CREATE, - Permission::CATEGORIES_UPDATE, - Permission::CATEGORIES_DELETE, - - Permission::SUPPLIERS_VIEW, - Permission::SUPPLIERS_CREATE, - Permission::SUPPLIERS_UPDATE, - Permission::SUPPLIERS_DELETE, Permission::CUSTOMERS_VIEW, - Permission::CUSTOMERS_CREATE, - Permission::CUSTOMERS_UPDATE, - Permission::CUSTOMERS_DELETE, Permission::PRODUCTS_VIEW, Permission::ORDERS_VIEW, - Permission::ORDERS_CREATE, - Permission::ORDERS_UPDATE, - Permission::ORDERS_SEND, - Permission::ORDERS_COMPLETE, - Permission::ORDERS_CANCEL, + + Permission::EMPLOYEE_ADVANCES_VIEW, + Permission::EMPLOYEE_ADVANCES_CREATE, + Permission::EMPLOYEE_ADVANCES_UPDATE, + Permission::EMPLOYEE_ADVANCES_DELETE, + Permission::EMPLOYEE_ADVANCES_PAY, + + Permission::PAYROLL_VIEW, ], self::NON_OPERATOR => [ diff --git a/app/Http/Controllers/Admin/Manage/OrderController.php b/app/Http/Controllers/Admin/Manage/OrderController.php index 522d697..469b341 100644 --- a/app/Http/Controllers/Admin/Manage/OrderController.php +++ b/app/Http/Controllers/Admin/Manage/OrderController.php @@ -41,6 +41,7 @@ public function create(Request $request): Response return Inertia::render('admin/manage/orders/Create', [ 'customers' => $this->orderService->customerOptions(), + 'marketings' => $this->orderService->marketingOptions(), 'catalog' => $this->orderService->catalogItems(user: $user), 'channels' => OrderChannel::selectOptions(), 'storePriceTypes' => $this->orderService->storePriceTypeOptions(), @@ -68,6 +69,7 @@ public function edit(Order $order): Response|RedirectResponse return Inertia::render('admin/manage/orders/Edit', [ 'order' => $this->orderService->findForEdit($order), 'customers' => $this->orderService->customerOptions(), + 'marketings' => $this->orderService->marketingOptions(), 'catalog' => $this->orderService->catalogItems($order), 'channels' => OrderChannel::selectOptions(), 'storePriceTypes' => $this->orderService->storePriceTypeOptions(), diff --git a/app/Http/Requests/Admin/Manage/OrderRequest.php b/app/Http/Requests/Admin/Manage/OrderRequest.php index e9a9081..6102ae2 100644 --- a/app/Http/Requests/Admin/Manage/OrderRequest.php +++ b/app/Http/Requests/Admin/Manage/OrderRequest.php @@ -28,6 +28,7 @@ public function rules(): array { $rules = [ 'customer_id' => ['nullable', 'integer', Rule::exists('customers', 'id')->whereNull('deleted_at')], + 'marketing_id' => ['nullable', 'integer', Rule::exists('users', 'id')->whereNull('deleted_at')], 'channel' => ['required', Rule::enum(OrderChannel::class)], 'price_type' => ['required', Rule::enum(PriceType::class)], 'discount' => ['nullable', 'integer', 'min:0'], @@ -54,6 +55,7 @@ public function attributes(): array { return [ 'customer_id' => 'pelanggan', + 'marketing_id' => 'marketing', 'channel' => 'channel', 'price_type' => 'tipe harga', 'discount' => 'diskon', diff --git a/app/Models/Order.php b/app/Models/Order.php index 3a5ad43..a9593b3 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -54,6 +54,11 @@ public function createdBy(): BelongsTo return $this->belongsTo(User::class, 'created_by_id'); } + public function marketing(): BelongsTo + { + return $this->belongsTo(User::class, 'marketing_id'); + } + public function customer(): BelongsTo { return $this->belongsTo(Customer::class); diff --git a/app/Services/Manage/OrderService.php b/app/Services/Manage/OrderService.php index 7d80e2b..75dc1b0 100644 --- a/app/Services/Manage/OrderService.php +++ b/app/Services/Manage/OrderService.php @@ -41,6 +41,7 @@ public function paginateForIndex(array $tableQuery, User $user): LengthAwarePagi 'items.productVariant.product:id,name', 'items.productVariant:id,product_id,name', ]) + ->when($user->hasRole('marketing'), fn (Builder $query) => $query->where('marketing_id', $user->id)) ->when($tableQuery['search'] !== '', function (Builder $query) use ($tableQuery): void { $search = $tableQuery['search']; $query->where(function (Builder $query) use ($search): void { @@ -87,6 +88,24 @@ public function customerOptions(): array ->all(); } + /** + * @return list + */ + public function marketingOptions(): array + { + return User::query() + ->active() + ->whereHas('roles', fn ($q) => $q->where('name', 'marketing')) + ->with('profile:user_id,full_name') + ->orderBy('username') + ->get(['id', 'username']) + ->map(fn (User $user) => [ + 'value' => $user->id, + 'label' => $user->profile?->full_name ?? $user->username, + ]) + ->all(); + } + /** * @return list */ @@ -301,6 +320,7 @@ public function create(array $validated, User $user): Order $order = Order::create([ 'customer_id' => $validated['customer_id'] ?? null, + 'marketing_id' => $validated['marketing_id'] ?? null, 'channel' => $channel, 'price_type' => $priceType, 'status' => OrderStatus::PENDING, @@ -374,6 +394,7 @@ public function update(Order $order, array $validated): void $channel = OrderChannel::from($validated['channel']); $order->customer_id = $validated['customer_id'] ?? null; + $order->marketing_id = $validated['marketing_id'] ?? null; $order->channel = $channel; $order->price_type = $priceType; $order->subtotal = $subtotal; diff --git a/database/migrations/2026_06_12_100001_create_orders_table.php b/database/migrations/2026_06_12_100001_create_orders_table.php index a824761..4a4577e 100644 --- a/database/migrations/2026_06_12_100001_create_orders_table.php +++ b/database/migrations/2026_06_12_100001_create_orders_table.php @@ -15,6 +15,7 @@ public function up(): void $table->id(); $table->foreignId('customer_id')->nullable()->constrained()->nullOnDelete(); + $table->foreignId('marketing_id')->nullable()->constrained('users')->nullOnDelete(); $table->string('order_number', 30)->unique(); $table->enum('channel', array_column(OrderChannel::cases(), 'value')); diff --git a/resources/js/components/admin/manage/orders/OrderPosForm.vue b/resources/js/components/admin/manage/orders/OrderPosForm.vue index 4c21adf..82acae6 100644 --- a/resources/js/components/admin/manage/orders/OrderPosForm.vue +++ b/resources/js/components/admin/manage/orders/OrderPosForm.vue @@ -1,8 +1,9 @@