Fixed transfer category delete and changed type issue..

This commit is contained in:
Cüneyt Şentürk 2023-04-05 14:40:51 +03:00
parent e4154a7e38
commit 15a992365d
4 changed files with 22 additions and 8 deletions

View File

@ -31,6 +31,13 @@ class DeleteCategory extends Job implements ShouldDelete
*/ */
public function authorize(): void public function authorize(): void
{ {
// Can not delete transfer category
if ($this->model->isTransferCategory()) {
$message = trans('messages.error.transfer_category', ['type' => $this->model->name]);
throw new \Exception($message);
}
// Can not delete the last category by type // Can not delete the last category by type
if (Category::where('type', $this->model->type)->count() == 1) { if (Category::where('type', $this->model->type)->count() == 1) {
$message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->model->type . 's', 1))]); $message = trans('messages.error.last_category', ['type' => strtolower(trans_choice('general.' . $this->model->type . 's', 1))]);

View File

@ -25,7 +25,8 @@ return [
'not_user_company' => 'Error: You are not allowed to manage this company!', 'not_user_company' => 'Error: You are not allowed to manage this company!',
'customer' => 'Error: User not created! :name already uses this email address.', 'customer' => 'Error: User not created! :name already uses this email address.',
'no_file' => 'Error: No file selected!', 'no_file' => 'Error: No file selected!',
'last_category' => 'Error: Can not delete the last :type category!', 'last_category' => 'Error: Can not delete the last <b>:type</b> category!',
'transfer_category' => 'Error: Can not delete the transfer <b>:type</b> category!',
'change_type' => 'Error: Can not change the type because it has :text related!', 'change_type' => 'Error: Can not change the type because it has :text related!',
'invalid_apikey' => 'Error: The API Key entered is invalid!', 'invalid_apikey' => 'Error: The API Key entered is invalid!',
'import_column' => 'Error: :message Column name: :column. Line number: :line.', 'import_column' => 'Error: :message Column name: :column. Line number: :line.',

View File

@ -17,21 +17,23 @@
<x-form.group.color name="color" label="{{ trans('general.color') }}" /> <x-form.group.color name="color" label="{{ trans('general.color') }}" />
@if ($type_disabled) @if ($type_disabled)
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" disabled /> <x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" v-disabled="true" />
<input type="hidden" name="type" value="{{ $category->type }}" /> <input type="hidden" name="type" value="{{ $category->type }}" />
@else @else
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" change="updateParentCategories" /> <x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" change="updateParentCategories" />
@endif
<x-form.group.select name="parent_id" label="{{ trans('general.parent') . ' ' . trans_choice('general.categories', 1) }}" :options="$parent_categories" not-required dynamicOptions="categoriesBasedTypes" sort-options="false" /> <x-form.group.select name="parent_id" label="{{ trans('general.parent') . ' ' . trans_choice('general.categories', 1) }}" :options="$parent_categories" not-required dynamicOptions="categoriesBasedTypes" sort-options="false" />
<x-form.input.hidden name="parent_category_id" value="{{ $category->parent_id }}" /> <x-form.input.hidden name="parent_category_id" value="{{ $category->parent_id }}" />
<x-form.input.hidden name="categories" value="{{ json_encode($categories) }}" /> <x-form.input.hidden name="categories" value="{{ json_encode($categories) }}" />
@endif
</x-slot> </x-slot>
</x-form.section> </x-form.section>
@if (! $type_disabled)
<x-form.group.switch name="enabled" label="{{ trans('general.enabled') }}" /> <x-form.group.switch name="enabled" label="{{ trans('general.enabled') }}" />
@endif
@can('update-settings-categories') @can('update-settings-categories')
<x-form.section> <x-form.section>

View File

@ -67,7 +67,11 @@
@foreach($categories as $item) @foreach($categories as $item)
<x-table.tr href="{{ route('categories.edit', $item->id) }}"> <x-table.tr href="{{ route('categories.edit', $item->id) }}">
<x-table.td kind="bulkaction"> <x-table.td kind="bulkaction">
<x-index.bulkaction.single id="{{ $item->id }}" name="{{ $item->name }}" /> <x-index.bulkaction.single
id="{{ $item->id }}"
name="{{ $item->name }}"
:disabled="($item->isTransferCategory()) ? true : false"
/>
</x-table.td> </x-table.td>
<x-table.td class="w-5/12"> <x-table.td class="w-5/12">