diff --git a/app/Http/Controllers/Settings/Categories.php b/app/Http/Controllers/Settings/Categories.php
index 4bbad1a59..b0a6d85e9 100644
--- a/app/Http/Controllers/Settings/Categories.php
+++ b/app/Http/Controllers/Settings/Categories.php
@@ -171,4 +171,11 @@ class Categories extends Controller
return redirect('settings/categories');
}
+
+ public function category(Request $request)
+ {
+ $category = Category::create($request->all());
+
+ return response()->json($category);
+ }
}
diff --git a/resources/views/expenses/bills/create.blade.php b/resources/views/expenses/bills/create.blade.php
index 09a589c69..e340e50db 100644
--- a/resources/views/expenses/bills/create.blade.php
+++ b/resources/views/expenses/bills/create.blade.php
@@ -98,7 +98,17 @@
- {{ Form::selectGroup('category_id', trans_choice('general.categories', 1), 'folder-open-o', $categories) }}
+
{{ Form::textareaGroup('notes', trans_choice('general.notes', 2)) }}
@@ -118,11 +128,13 @@
+
@endpush
@push('css')
+
@endpush
@push('scripts')
@@ -401,5 +413,89 @@
}
});
});
+
+ function createCategory() {
+ $('#modal-create-category').remove();
+
+ modal = '';
+ modal += '
';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+ modal += ' {!! Form::hidden('type', 'expense', []) !!}';
+ modal += ' {!! Form::hidden('enabled', '1', []) !!}';
+ modal += '
';
+ modal += ' {!! Form::close() !!}';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+
+ $('body').append(modal);
+
+ $('#category-color-picker').colorpicker();
+
+ $('#modal-create-category').modal('show');
+ }
+
+ $(document).on('click', '#button-create-category', function (e) {
+ $('#modal-create-category .modal-header').before('');
+
+ $.ajax({
+ url: '{{ url("settings/categories/category") }}',
+ type: 'POST',
+ dataType: 'JSON',
+ data: $("#form-create-category").serialize(),
+ beforeSend: function () {
+ $(".form-group").removeClass("has-error");
+ $(".help-block").remove();
+ },
+ success: function(data) {
+ $('#span-loading').remove();
+
+ $('#modal-create-category').modal('hide');
+
+ $("#category_id").append('');
+ $("#category_id").select2('refresh');
+ },
+ error: function(error, textStatus, errorThrown) {
+ $('#span-loading').remove();
+
+ if (error.responseJSON.name) {
+ $("input[name='name']").parent().parent().addClass('has-error');
+ $("input[name='name']").parent().after('' + error.responseJSON.name + '
');
+ }
+
+ if (error.responseJSON.color) {
+ $("input[name='color']").parent().parent().addClass('has-error');
+ $("input[name='color']").parent().after('' + error.responseJSON.color + '
');
+ }
+ }
+ });
+ });
@endpush
diff --git a/resources/views/expenses/payments/create.blade.php b/resources/views/expenses/payments/create.blade.php
index df8704f4d..b61be999c 100644
--- a/resources/views/expenses/payments/create.blade.php
+++ b/resources/views/expenses/payments/create.blade.php
@@ -26,7 +26,17 @@
{{ Form::textareaGroup('description', trans('general.description')) }}
- {{ Form::selectGroup('category_id', trans_choice('general.categories', 1), 'folder-open-o', $categories) }}
+
{!! Form::label('vendor_id', trans_choice('general.vendors', 1), ['class' => 'control-label']) !!}
@@ -59,11 +69,13 @@
@push('js')
+
@endpush
@push('css')
+
@endpush
@push('scripts')
@@ -223,5 +235,89 @@
}
});
});
+
+ function createCategory() {
+ $('#modal-create-category').remove();
+
+ modal = '
';
+ modal += '
';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+ modal += ' {!! Form::hidden('type', 'expense', []) !!}';
+ modal += ' {!! Form::hidden('enabled', '1', []) !!}';
+ modal += '
';
+ modal += ' {!! Form::close() !!}';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+
+ $('body').append(modal);
+
+ $('#category-color-picker').colorpicker();
+
+ $('#modal-create-category').modal('show');
+ }
+
+ $(document).on('click', '#button-create-category', function (e) {
+ $('#modal-create-category .modal-header').before('
');
+
+ $.ajax({
+ url: '{{ url("settings/categories/category") }}',
+ type: 'POST',
+ dataType: 'JSON',
+ data: $("#form-create-category").serialize(),
+ beforeSend: function () {
+ $(".form-group").removeClass("has-error");
+ $(".help-block").remove();
+ },
+ success: function(data) {
+ $('#span-loading').remove();
+
+ $('#modal-create-category').modal('hide');
+
+ $("#category_id").append('
');
+ $("#category_id").select2('refresh');
+ },
+ error: function(error, textStatus, errorThrown) {
+ $('#span-loading').remove();
+
+ if (error.responseJSON.name) {
+ $("input[name='name']").parent().parent().addClass('has-error');
+ $("input[name='name']").parent().after('
' + error.responseJSON.name + '
');
+ }
+
+ if (error.responseJSON.color) {
+ $("input[name='color']").parent().parent().addClass('has-error');
+ $("input[name='color']").parent().after('
' + error.responseJSON.color + '
');
+ }
+ }
+ });
+ });
@endpush
diff --git a/resources/views/incomes/invoices/create.blade.php b/resources/views/incomes/invoices/create.blade.php
index 15d0afb86..7b6a78787 100644
--- a/resources/views/incomes/invoices/create.blade.php
+++ b/resources/views/incomes/invoices/create.blade.php
@@ -98,7 +98,17 @@
- {{ Form::selectGroup('category_id', trans_choice('general.categories', 1), 'folder-open-o', $categories) }}
+
{{ Form::textareaGroup('notes', trans_choice('general.notes', 2)) }}
@@ -119,11 +129,13 @@
+
@endpush
@push('css')
+
@endpush
@push('scripts')
@@ -400,5 +412,89 @@
}
});
});
+
+ function createCategory() {
+ $('#modal-create-category').remove();
+
+ modal = '';
+ modal += '
';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+ modal += ' {!! Form::hidden('type', 'income', []) !!}';
+ modal += ' {!! Form::hidden('enabled', '1', []) !!}';
+ modal += '
';
+ modal += ' {!! Form::close() !!}';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+
+ $('body').append(modal);
+
+ $('#category-color-picker').colorpicker();
+
+ $('#modal-create-category').modal('show');
+ }
+
+ $(document).on('click', '#button-create-category', function (e) {
+ $('#modal-create-category .modal-header').before('');
+
+ $.ajax({
+ url: '{{ url("settings/categories/category") }}',
+ type: 'POST',
+ dataType: 'JSON',
+ data: $("#form-create-category").serialize(),
+ beforeSend: function () {
+ $(".form-group").removeClass("has-error");
+ $(".help-block").remove();
+ },
+ success: function(data) {
+ $('#span-loading').remove();
+
+ $('#modal-create-category').modal('hide');
+
+ $("#category_id").append('');
+ $("#category_id").select2('refresh');
+ },
+ error: function(error, textStatus, errorThrown) {
+ $('#span-loading').remove();
+
+ if (error.responseJSON.name) {
+ $("input[name='name']").parent().parent().addClass('has-error');
+ $("input[name='name']").parent().after('' + error.responseJSON.name + '
');
+ }
+
+ if (error.responseJSON.color) {
+ $("input[name='color']").parent().parent().addClass('has-error');
+ $("input[name='color']").parent().after('' + error.responseJSON.color + '
');
+ }
+ }
+ });
+ });
@endpush
diff --git a/resources/views/incomes/revenues/create.blade.php b/resources/views/incomes/revenues/create.blade.php
index 953ef1799..7dbf7c996 100644
--- a/resources/views/incomes/revenues/create.blade.php
+++ b/resources/views/incomes/revenues/create.blade.php
@@ -26,7 +26,17 @@
{{ Form::textareaGroup('description', trans('general.description')) }}
- {{ Form::selectGroup('category_id', trans_choice('general.categories', 1), 'folder-open-o', $categories) }}
+
{!! Form::label('customer_id', trans_choice('general.customers', 1), ['class' => 'control-label']) !!}
@@ -59,11 +69,13 @@
@push('js')
+
@endpush
@push('css')
+
@endpush
@push('scripts')
@@ -223,5 +235,89 @@
}
});
});
+
+ function createCategory() {
+ $('#modal-create-category').remove();
+
+ modal = '
';
+ modal += '
';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+ modal += ' {!! Form::hidden('type', 'income', []) !!}';
+ modal += ' {!! Form::hidden('enabled', '1', []) !!}';
+ modal += '
';
+ modal += ' {!! Form::close() !!}';
+ modal += '
';
+ modal += ' ';
+ modal += '
';
+ modal += '
';
+ modal += '
';
+
+ $('body').append(modal);
+
+ $('#category-color-picker').colorpicker();
+
+ $('#modal-create-category').modal('show');
+ }
+
+ $(document).on('click', '#button-create-category', function (e) {
+ $('#modal-create-category .modal-header').before('
');
+
+ $.ajax({
+ url: '{{ url("settings/categories/category") }}',
+ type: 'POST',
+ dataType: 'JSON',
+ data: $("#form-create-category").serialize(),
+ beforeSend: function () {
+ $(".form-group").removeClass("has-error");
+ $(".help-block").remove();
+ },
+ success: function(data) {
+ $('#span-loading').remove();
+
+ $('#modal-create-category').modal('hide');
+
+ $("#category_id").append('
');
+ $("#category_id").select2('refresh');
+ },
+ error: function(error, textStatus, errorThrown) {
+ $('#span-loading').remove();
+
+ if (error.responseJSON.name) {
+ $("input[name='name']").parent().parent().addClass('has-error');
+ $("input[name='name']").parent().after('
' + error.responseJSON.name + '
');
+ }
+
+ if (error.responseJSON.color) {
+ $("input[name='color']").parent().parent().addClass('has-error');
+ $("input[name='color']").parent().after('
' + error.responseJSON.color + '
');
+ }
+ }
+ });
+ });
@endpush
diff --git a/routes/web.php b/routes/web.php
index 8d3d90320..38937987f 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -101,6 +101,7 @@ Route::group(['middleware' => 'language'], function () {
});
Route::group(['prefix' => 'settings'], function () {
+ Route::post('categories/category', 'Settings\Categories@category');
Route::resource('categories', 'Settings\Categories');
Route::get('currencies/currency', 'Settings\Currencies@currency');
Route::get('currencies/config', 'Settings\Currencies@config');