diff --git a/app/Domains/Purchases/Http/Controllers/Company/ExpenseCategoriesController.php b/app/Domains/Purchases/Http/Controllers/Company/ExpenseCategoriesController.php deleted file mode 100644 index 403ceb4f..00000000 --- a/app/Domains/Purchases/Http/Controllers/Company/ExpenseCategoriesController.php +++ /dev/null @@ -1,95 +0,0 @@ -authorize('viewAny', ExpenseCategory::class); - - $limit = $request->has('limit') ? $request->limit : 5; - - $categories = ExpenseCategory::applyFilters($request->all()) - ->whereCompany() - ->latest() - ->paginateData($limit); - - return ExpenseCategoryResource::collection($categories); - } - - /** - * Store a newly created resource in storage. - * - * @param Request $request - * @return Response - */ - public function store(ExpenseCategoryRequest $request) - { - $this->authorize('create', ExpenseCategory::class); - - $category = ExpenseCategory::create($request->getExpenseCategoryPayload()); - - return new ExpenseCategoryResource($category); - } - - /** - * Display the specified resource. - * - * @return Response - */ - public function show(ExpenseCategory $category) - { - $this->authorize('view', $category); - - return new ExpenseCategoryResource($category); - } - - /** - * Update the specified resource in storage. - * - * @param Request $request - * @param ExpenseCategory $ExpenseCategory - * @return Response - */ - public function update(ExpenseCategoryRequest $request, ExpenseCategory $category) - { - $this->authorize('update', $category); - - $category->update($request->getExpenseCategoryPayload()); - - return new ExpenseCategoryResource($category); - } - - /** - * Remove the specified resource from storage. - * - * @return Response - */ - public function destroy(ExpenseCategory $category) - { - $this->authorize('delete', $category); - - if ($category->expenses() && $category->expenses()->count() > 0) { - return respondJson('expense_attached', 'Expense Attached'); - } - - $category->delete(); - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Domains/Purchases/Http/Controllers/Company/ExpensesController.php b/app/Domains/Purchases/Http/Controllers/Company/ExpensesController.php deleted file mode 100644 index 17cd5be5..00000000 --- a/app/Domains/Purchases/Http/Controllers/Company/ExpensesController.php +++ /dev/null @@ -1,200 +0,0 @@ -authorize('viewAny', Expense::class); - - $limit = $request->has('limit') ? $request->limit : 10; - - $expenses = Expense::with('category', 'creator', 'fields') - ->whereCompany() - ->leftJoin('customers', 'customers.id', '=', 'expenses.customer_id') - ->join('expense_categories', 'expense_categories.id', '=', 'expenses.expense_category_id') - ->applyFilters($request->all()) - ->select('expenses.*', 'expense_categories.name', 'customers.name as user_name') - ->paginateData($limit); - - return ExpenseResource::collection($expenses) - ->additional(['meta' => [ - 'expense_total_count' => Expense::whereCompany()->count(), - ]]); - } - - /** - * Store a newly created resource in storage. - * - * @return JsonResponse - */ - public function store(ExpenseRequest $request) - { - $this->authorize('create', Expense::class); - - $expense = $this->expenseService->create( - attributes: $request->getExpensePayload(), - taxes: $request->has('taxes') ? $request->input('taxes') : null, - receipt: $this->receipt($request), - customFields: $this->customFields($request), - ); - - return new ExpenseResource($expense); - } - - /** - * Display the specified resource. - * - * @return JsonResponse - */ - public function show(Expense $expense) - { - $this->authorize('view', $expense); - - $expense->load('taxes.taxType'); - - return new ExpenseResource($expense); - } - - /** - * Update the specified resource in storage. - * - * @return JsonResponse - */ - public function update(ExpenseRequest $request, Expense $expense) - { - $this->authorize('update', $expense); - - $expense = $this->expenseService->update( - expense: $expense, - attributes: $request->getExpensePayload(), - taxes: $request->has('taxes') ? $request->input('taxes') : null, - receipt: $this->receipt($request), - removeReceipt: (bool) $request->input('is_attachment_receipt_removed', false), - customFields: $this->customFields($request), - ); - - return new ExpenseResource($expense); - } - - public function delete(DeleteExpensesRequest $request) - { - $this->authorize('delete multiple expenses'); - - $ids = Expense::whereCompany() - ->whereIn('id', $request->ids) - ->pluck('id'); - - Expense::destroy($ids); - - return response()->json([ - 'success' => true, - ]); - } - - public function showReceipt(Expense $expense) - { - $this->authorize('view', $expense); - - $receipt = $this->expenseReceiptManager->first($expense); - - if ($receipt) { - return response()->file($receipt->path); - } - - return respondJson('receipt_does_not_exist', 'Receipt does not exist.'); - } - - public function uploadReceipt(UploadExpenseReceiptRequest $request, Expense $expense) - { - $this->authorize('update', $expense); - - $data = json_decode($request->attachment_receipt); - - if ($data) { - $this->expenseReceiptManager->attachBase64( - $expense, - $data->data, - $data->name, - $request->type === 'edit', - ); - } - - return response()->json([ - 'success' => 'Expense receipts uploaded successfully', - ], 200); - } - - public function downloadReceipt(Expense $expense) - { - $this->authorize('view', $expense); - - $receipt = $this->expenseReceiptManager->first($expense); - - if ($receipt) { - $response = response()->download($receipt->path, $receipt->fileName); - if (ob_get_contents()) { - ob_end_clean(); - } - - return $response; - } - - return response()->json([ - 'error' => 'receipt_not_found', - ]); - } - - /** @return array|null */ - private function customFields(ExpenseRequest $request): ?array - { - $customFields = $request->input('customFields'); - - if (! $customFields) { - return null; - } - - if (is_string($customFields)) { - $customFields = json_decode($customFields); - } - - return is_array($customFields) ? $customFields : null; - } - - private function receipt(ExpenseRequest $request): ?PendingExpenseReceipt - { - $receipt = $request->file('attachment_receipt'); - - if (! $receipt) { - return null; - } - - return new PendingExpenseReceipt( - $receipt->getPathname(), - $receipt->getClientOriginalName(), - ); - } -} diff --git a/app/Domains/Purchases/Http/Controllers/CustomerPortal/ExpensesController.php b/app/Domains/Purchases/Http/Controllers/CustomerPortal/ExpensesController.php deleted file mode 100644 index cd2968d9..00000000 --- a/app/Domains/Purchases/Http/Controllers/CustomerPortal/ExpensesController.php +++ /dev/null @@ -1,60 +0,0 @@ -has('limit') ? $request->limit : 10; - - $expenses = Expense::with('category', 'creator', 'fields') - ->whereUser(Auth::guard('customer')->id()) - ->applyFilters($request->only([ - 'expense_category_id', - 'from_date', - 'to_date', - 'orderByField', - 'orderBy', - ])) - ->paginateData($limit); - - return ExpenseResource::collection($expenses) - ->additional(['meta' => [ - 'expenseTotalCount' => Expense::whereCustomer(Auth::guard('customer')->id())->count(), - ]]); - } - - /** - * Display the specified resource. - * - * @param Expense $expense - * @return Response - */ - public function show(Company $company, $id) - { - $expense = $company->expenses() - ->whereUser(Auth::guard('customer')->id()) - ->where('id', $id) - ->first(); - - if (! $expense) { - return response()->json(['error' => 'expense_not_found'], 404); - } - - return new ExpenseResource($expense); - } -} diff --git a/app/Domains/Purchases/Http/Requests/DeleteExpensesRequest.php b/app/Domains/Purchases/Http/Requests/DeleteExpensesRequest.php deleted file mode 100644 index 2a2105ec..00000000 --- a/app/Domains/Purchases/Http/Requests/DeleteExpensesRequest.php +++ /dev/null @@ -1,33 +0,0 @@ - [ - 'required', - ], - 'ids.*' => [ - 'required', - Rule::exists('expenses', 'id'), - ], - ]; - } -} diff --git a/app/Domains/Purchases/Http/Requests/ExpenseCategoryRequest.php b/app/Domains/Purchases/Http/Requests/ExpenseCategoryRequest.php deleted file mode 100644 index 49a7f381..00000000 --- a/app/Domains/Purchases/Http/Requests/ExpenseCategoryRequest.php +++ /dev/null @@ -1,40 +0,0 @@ - [ - 'required', - ], - 'description' => [ - 'nullable', - ], - ]; - } - - public function getExpenseCategoryPayload() - { - return collect($this->validated()) - ->merge([ - 'company_id' => $this->header('company'), - ]) - ->toArray(); - } -} diff --git a/app/Domains/Purchases/Http/Requests/ExpenseRequest.php b/app/Domains/Purchases/Http/Requests/ExpenseRequest.php deleted file mode 100644 index 7f83a548..00000000 --- a/app/Domains/Purchases/Http/Requests/ExpenseRequest.php +++ /dev/null @@ -1,148 +0,0 @@ -input('taxes'))) { - $taxes = json_decode($this->input('taxes'), true); - - $this->merge([ - 'taxes' => json_last_error() === JSON_ERROR_NONE ? $taxes : null, - ]); - } - } - - /** - * Determine if the user is authorized to make this request. - */ - public function authorize(): bool - { - return true; - } - - /** - * Get the validation rules that apply to the request. - */ - public function rules(): array - { - $companyCurrency = CompanySetting::getSetting('currency', $this->header('company')); - - $rules = [ - 'expense_date' => [ - 'required', - ], - 'expense_number' => [ - 'nullable', - 'string', - 'max:255', - ], - 'expense_category_id' => [ - 'required', - ], - 'exchange_rate' => [ - 'nullable', - ], - 'payment_method_id' => [ - 'nullable', - ], - 'amount' => [ - 'required', - 'integer', - 'min:0', - ], - 'customer_id' => [ - 'nullable', - ], - 'notes' => [ - 'nullable', - ], - 'currency_id' => [ - 'required', - ], - 'attachment_receipt' => [ - 'nullable', - 'file', - 'mimes:jpg,png,pdf,doc,docx,xls,xlsx,ppt,pptx', - 'max:20000', - ], - 'taxes' => [ - 'sometimes', - 'array', - ], - 'taxes.*' => [ - 'required', - 'array:tax_type_id,amount', - ], - 'taxes.*.tax_type_id' => [ - 'required', - 'integer', - 'distinct', - Rule::exists('tax_types', 'id') - ->where('company_id', $this->header('company')) - ->where('type', TaxType::TYPE_GENERAL) - ->where('transaction_type', TaxType::TRANSACTION_TYPE_PURCHASES), - ], - 'taxes.*.amount' => [ - 'required', - 'integer', - 'min:0', - ], - ]; - - if ($companyCurrency && $this->currency_id) { - if ($companyCurrency !== $this->currency_id) { - $rules['exchange_rate'] = [ - 'required', - ]; - } - } - - return $rules; - } - - public function withValidator(Validator $validator): void - { - $validator->after(function (Validator $validator): void { - $taxes = $this->input('taxes'); - - if (! is_array($taxes) || $validator->errors()->has('taxes') || $validator->errors()->has('taxes.*')) { - return; - } - - $totalTaxAmount = collect($taxes)->sum( - fn (mixed $tax): int => is_array($tax) ? (int) ($tax['amount'] ?? 0) : 0 - ); - - if ($totalTaxAmount > (int) $this->input('amount')) { - $validator->errors()->add('taxes', 'The total tax amount may not exceed the expense amount.'); - } - }); - } - - public function getExpensePayload() - { - $company_currency = CompanySetting::getSetting('currency', $this->header('company')); - $current_currency = $this->currency_id; - $exchange_rate = $company_currency != $current_currency ? $this->exchange_rate : 1; - - return collect($this->validated()) - ->except('taxes') - ->merge([ - 'creator_id' => $this->user()->id, - 'company_id' => $this->header('company'), - 'exchange_rate' => $exchange_rate, - 'base_amount' => $this->amount * $exchange_rate, - 'currency_id' => $current_currency, - ]) - ->toArray(); - } -} diff --git a/app/Domains/Purchases/Http/Requests/UploadExpenseReceiptRequest.php b/app/Domains/Purchases/Http/Requests/UploadExpenseReceiptRequest.php deleted file mode 100644 index 0c2d802d..00000000 --- a/app/Domains/Purchases/Http/Requests/UploadExpenseReceiptRequest.php +++ /dev/null @@ -1,30 +0,0 @@ - [ - 'nullable', - new Base64Mime(['gif', 'jpg', 'png']), - ], - ]; - } -} diff --git a/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseCategoryResource.php b/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseCategoryResource.php deleted file mode 100644 index 8e87dad6..00000000 --- a/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseCategoryResource.php +++ /dev/null @@ -1,30 +0,0 @@ - $this->id, - 'name' => $this->name, - 'description' => $this->description, - 'company_id' => $this->company_id, - 'amount' => $this->amount, - 'formatted_created_at' => $this->formattedCreatedAt, - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseResource.php b/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseResource.php deleted file mode 100644 index b0e121d8..00000000 --- a/app/Domains/Purchases/Http/Resources/CustomerPortal/ExpenseResource.php +++ /dev/null @@ -1,60 +0,0 @@ - $this->id, - 'expense_date' => $this->expense_date, - 'expense_number' => $this->expense_number, - 'amount' => $this->amount, - 'notes' => $this->notes, - 'customer_id' => $this->customer_id, - 'attachment_receipt_url' => $this->receipt_url, - 'attachment_receipt' => $this->receipt, - 'attachment_receipt_meta' => $this->receipt_meta, - 'company_id' => $this->company_id, - 'expense_category_id' => $this->expense_category_id, - 'formatted_expense_date' => $this->formattedExpenseDate, - 'formatted_created_at' => $this->formattedCreatedAt, - 'exchange_rate' => $this->exchange_rate, - 'currency_id' => $this->currency_id, - 'base_amount' => $this->base_amount, - 'payment_method_id' => $this->payment_method_id, - 'customer' => $this->when($this->customer()->exists(), function () { - return new CustomerResource($this->customer); - }), - 'expense_category' => $this->when($this->category()->exists(), function () { - return new ExpenseCategoryResource($this->category); - }), - 'fields' => $this->when($this->fields()->exists(), function () { - return CustomFieldValueResource::collection($this->fields); - }), - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - 'currency' => $this->when($this->currency()->exists(), function () { - return new CurrencyResource($this->currency); - }), - 'payment_method' => $this->when($this->paymentMethod()->exists(), function () { - return new PaymentMethodResource($this->paymentMethod); - }), - ]; - } -} diff --git a/app/Domains/Purchases/Http/Resources/ExpenseCategoryResource.php b/app/Domains/Purchases/Http/Resources/ExpenseCategoryResource.php deleted file mode 100644 index f3e0ef44..00000000 --- a/app/Domains/Purchases/Http/Resources/ExpenseCategoryResource.php +++ /dev/null @@ -1,30 +0,0 @@ - $this->id, - 'name' => $this->name, - 'description' => $this->description, - 'company_id' => $this->company_id, - 'amount' => $this->amount, - 'formatted_created_at' => $this->formattedCreatedAt, - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - ]; - } -} diff --git a/app/Domains/Purchases/Http/Resources/ExpenseResource.php b/app/Domains/Purchases/Http/Resources/ExpenseResource.php deleted file mode 100644 index dd97bf23..00000000 --- a/app/Domains/Purchases/Http/Resources/ExpenseResource.php +++ /dev/null @@ -1,67 +0,0 @@ - $this->id, - 'expense_date' => $this->expense_date, - 'expense_number' => $this->expense_number, - 'amount' => $this->amount, - 'notes' => $this->notes, - 'customer_id' => $this->customer_id, - 'attachment_receipt_url' => $this->receipt_url, - 'attachment_receipt' => $this->receipt, - 'attachment_receipt_meta' => $this->receipt_meta, - 'company_id' => $this->company_id, - 'expense_category_id' => $this->expense_category_id, - 'creator_id' => $this->creator_id, - 'formatted_expense_date' => $this->formattedExpenseDate, - 'formatted_created_at' => $this->formattedCreatedAt, - 'exchange_rate' => $this->exchange_rate, - 'currency_id' => $this->currency_id, - 'base_amount' => $this->base_amount, - 'payment_method_id' => $this->payment_method_id, - 'taxes' => TaxResource::collection($this->whenLoaded('taxes')), - 'customer' => $this->when($this->customer()->exists(), function () { - return new CustomerResource($this->customer); - }), - 'expense_category' => $this->when($this->category()->exists(), function () { - return new ExpenseCategoryResource($this->category); - }), - 'creator' => $this->when($this->creator()->exists(), function () { - return new UserResource($this->creator); - }), - 'fields' => $this->when($this->fields()->exists(), function () { - return CustomFieldValueResource::collection($this->fields); - }), - 'company' => $this->when($this->company()->exists(), function () { - return new CompanyResource($this->company); - }), - 'currency' => $this->when($this->currency()->exists(), function () { - return new CurrencyResource($this->currency); - }), - 'payment_method' => $this->when($this->paymentMethod()->exists(), function () { - return new PaymentMethodResource($this->paymentMethod); - }), - ]; - } -} diff --git a/app/Domains/Purchases/Models/Expense.php b/app/Domains/Purchases/Models/Expense.php deleted file mode 100644 index e56a8af9..00000000 --- a/app/Domains/Purchases/Models/Expense.php +++ /dev/null @@ -1,266 +0,0 @@ - 'string', - 'exchange_rate' => 'float', - ]; - } - - public function registerMediaCollections(): void - { - $this->addMediaCollection('receipts'); - } - - public function category(): BelongsTo - { - return $this->belongsTo(ExpenseCategory::class, 'expense_category_id'); - } - - public function customer(): BelongsTo - { - return $this->belongsTo(Customer::class, 'customer_id'); - } - - public function company(): BelongsTo - { - return $this->belongsTo(Company::class, 'company_id'); - } - - public function paymentMethod(): BelongsTo - { - return $this->belongsTo(PaymentMethod::class); - } - - public function currency(): BelongsTo - { - return $this->belongsTo(Currency::class, 'currency_id'); - } - - public function creator(): BelongsTo - { - return $this->belongsTo(User::class, 'creator_id'); - } - - public function taxes(): HasMany - { - return $this->hasMany(Tax::class); - } - - public function getFormattedExpenseDateAttribute(mixed $value): string - { - $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id); - - return Carbon::parse($this->expense_date)->translatedFormat($dateFormat); - } - - public function getFormattedCreatedAtAttribute(mixed $value): string - { - $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id); - - return Carbon::parse($this->created_at)->translatedFormat($dateFormat); - } - - public function getReceiptUrlAttribute(mixed $value): ?array - { - $media = $this->getFirstMedia('receipts'); - - if ($media) { - return [ - 'url' => '/reports/expenses/'.$this->id.'/receipt', - 'type' => $media->type, - ]; - } - - return null; - } - - public function getReceiptAttribute(mixed $value): ?string - { - $media = $this->getFirstMedia('receipts'); - - if ($media) { - return $media->getPath(); - } - - return null; - } - - public function getReceiptMetaAttribute(mixed $value): ?Media - { - $media = $this->getFirstMedia('receipts'); - - if ($media) { - return $media; - } - - return null; - } - - public function scopeExpensesBetween(Builder $query, Carbon $start, Carbon $end): Builder - { - return $query->whereBetween( - 'expenses.expense_date', - [$start->format('Y-m-d'), $end->format('Y-m-d')] - ); - } - - public function scopeWhereCategoryName(Builder $query, string $search): void - { - foreach (explode(' ', $search) as $term) { - $query->whereHas('category', function ($query) use ($term) { - $query->where('name', 'LIKE', '%'.$term.'%'); - }); - } - } - - public function scopeWhereNotes(Builder $query, string $search): void - { - $query->where('notes', 'LIKE', '%'.$search.'%'); - } - - public function scopeWhereCategory(Builder $query, int $categoryId): Builder - { - return $query->where('expenses.expense_category_id', $categoryId); - } - - public function scopeWhereUser(Builder $query, int $customer_id): Builder - { - return $query->where('expenses.customer_id', $customer_id); - } - - /** - * Apply multiple filter conditions including category, customer, expense, date range, ordering, and search. - */ - public function scopeApplyFilters(Builder $query, array $filters): void - { - $filters = collect($filters); - - if ($filters->get('expense_category_id')) { - $query->whereCategory($filters->get('expense_category_id')); - } - - if ($filters->get('customer_id')) { - $query->whereUser($filters->get('customer_id')); - } - - if ($filters->get('expense_id')) { - $query->whereExpense($filters->get('expense_id')); - } - - if ($filters->get('from_date') && $filters->get('to_date')) { - $start = Carbon::createFromFormat('Y-m-d', $filters->get('from_date')); - $end = Carbon::createFromFormat('Y-m-d', $filters->get('to_date')); - $query->expensesBetween($start, $end); - } - - if ($filters->get('orderByField') || $filters->get('orderBy')) { - $field = $filters->get('orderByField') ? $filters->get('orderByField') : 'expense_date'; - $orderBy = $filters->get('orderBy') ? $filters->get('orderBy') : 'asc'; - $query->whereOrder($field, $orderBy); - } - - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - } - - public function scopeWhereExpense(Builder $query, int $expense_id): void - { - $query->orWhere('id', $expense_id); - } - - public function scopeWhereSearch(Builder $query, string $search): void - { - foreach (explode(' ', $search) as $term) { - $query->whereHas('category', function ($query) use ($term) { - $query->where('name', 'LIKE', '%'.$term.'%'); - }) - ->orWhere('notes', 'LIKE', '%'.$term.'%'); - } - } - - public function scopeWhereOrder(Builder $query, string $orderByField, string $orderBy): void - { - SafeOrderBy::apply($query, $orderByField, $orderBy); - } - - public function scopeWhereCompany(Builder $query): void - { - $query->where('expenses.company_id', request()->header('company')); - } - - public function scopeWhereCompanyId(Builder $query, int $company): void - { - $query->where('expenses.company_id', $company); - } - - /** - * @return LengthAwarePaginator|Collection - */ - public function scopePaginateData(Builder $query, string $limit) - { - if ($limit == 'all') { - return $query->get(); - } - - return $query->paginate($limit); - } - - public function scopeExpensesAttributes(Builder $query): void - { - $query->select( - DB::raw(' - count(*) as expenses_count, - sum(base_amount) as total_amount, - expense_category_id') - ) - ->groupBy('expense_category_id'); - } -} diff --git a/app/Domains/Purchases/Models/ExpenseCategory.php b/app/Domains/Purchases/Models/ExpenseCategory.php deleted file mode 100644 index 30f66ce4..00000000 --- a/app/Domains/Purchases/Models/ExpenseCategory.php +++ /dev/null @@ -1,99 +0,0 @@ -hasMany(Expense::class); - } - - public function company(): BelongsTo - { - return $this->belongsTo(Company::class); - } - - public function getFormattedCreatedAtAttribute(mixed $value): string - { - $dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id); - - return Carbon::parse($this->created_at)->format($dateFormat); - } - - public function getAmountAttribute(): float - { - return $this->expenses()->sum('amount'); - } - - public function scopeWhereCompany(Builder $query): void - { - $query->where('company_id', request()->header('company')); - } - - public function scopeWhereCategory(Builder $query, int $category_id): void - { - $query->orWhere('id', $category_id); - } - - public function scopeWhereSearch(Builder $query, string $search): void - { - $query->where('name', 'LIKE', '%'.$search.'%'); - } - - /** - * Apply multiple filter conditions including category, company, and search. - */ - public function scopeApplyFilters(Builder $query, array $filters): void - { - $filters = collect($filters); - - if ($filters->get('category_id')) { - $query->whereCategory($filters->get('category_id')); - } - - if ($filters->get('company_id')) { - $query->whereCompany($filters->get('company_id')); - } - - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - } - - /** - * @return LengthAwarePaginator|Collection - */ - public function scopePaginateData(Builder $query, string $limit) - { - if ($limit == 'all') { - return $query->get(); - } - - return $query->paginate($limit); - } -} diff --git a/app/Domains/Purchases/Policies/ExpenseCategoryPolicy.php b/app/Domains/Purchases/Policies/ExpenseCategoryPolicy.php deleted file mode 100644 index 6939af5f..00000000 --- a/app/Domains/Purchases/Policies/ExpenseCategoryPolicy.php +++ /dev/null @@ -1,112 +0,0 @@ -hasCompany($expenseCategory->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can create models. - * - * @return mixed - */ - public function create(User $user): bool - { - if (BouncerFacade::can('view-expense', Expense::class)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can update the model. - * - * @return mixed - */ - public function update(User $user, ExpenseCategory $expenseCategory): bool - { - if (BouncerFacade::can('view-expense', Expense::class) && $user->hasCompany($expenseCategory->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can delete the model. - * - * @return mixed - */ - public function delete(User $user, ExpenseCategory $expenseCategory): bool - { - if (BouncerFacade::can('view-expense', Expense::class) && $user->hasCompany($expenseCategory->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can restore the model. - * - * @return mixed - */ - public function restore(User $user, ExpenseCategory $expenseCategory): bool - { - if (BouncerFacade::can('view-expense', Expense::class) && $user->hasCompany($expenseCategory->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can permanently delete the model. - * - * @return mixed - */ - public function forceDelete(User $user, ExpenseCategory $expenseCategory): bool - { - if (BouncerFacade::can('view-expense', Expense::class) && $user->hasCompany($expenseCategory->company_id)) { - return true; - } - - return false; - } -} diff --git a/app/Domains/Purchases/Policies/ExpensePolicy.php b/app/Domains/Purchases/Policies/ExpensePolicy.php deleted file mode 100644 index e4e5edd5..00000000 --- a/app/Domains/Purchases/Policies/ExpensePolicy.php +++ /dev/null @@ -1,125 +0,0 @@ -hasCompany($expense->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can create models. - * - * @return mixed - */ - public function create(User $user): bool - { - if (BouncerFacade::can('create-expense', Expense::class)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can update the model. - * - * @return mixed - */ - public function update(User $user, Expense $expense): bool - { - if (BouncerFacade::can('edit-expense', $expense) && $user->hasCompany($expense->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can delete the model. - * - * @return mixed - */ - public function delete(User $user, Expense $expense): bool - { - if (BouncerFacade::can('delete-expense', $expense) && $user->hasCompany($expense->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can restore the model. - * - * @return mixed - */ - public function restore(User $user, Expense $expense): bool - { - if (BouncerFacade::can('delete-expense', $expense) && $user->hasCompany($expense->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can permanently delete the model. - * - * @return mixed - */ - public function forceDelete(User $user, Expense $expense): bool - { - if (BouncerFacade::can('delete-expense', $expense) && $user->hasCompany($expense->company_id)) { - return true; - } - - return false; - } - - /** - * Determine whether the user can delete models. - * - * @return mixed - */ - public function deleteMultiple(User $user) - { - if (BouncerFacade::can('delete-expense', Expense::class)) { - return true; - } - - return false; - } -}