diff --git a/app/Http/Controllers/Expenses/Vendors.php b/app/Http/Controllers/Expenses/Vendors.php index a067894fb..f7eab2142 100644 --- a/app/Http/Controllers/Expenses/Vendors.php +++ b/app/Http/Controllers/Expenses/Vendors.php @@ -140,4 +140,11 @@ class Vendors extends Controller return response()->json($vendor); } + + public function vendor(Request $request) + { + $vendor = Vendor::create($request->all()); + + return response()->json($vendor); + } } diff --git a/app/Http/Controllers/Incomes/Customers.php b/app/Http/Controllers/Incomes/Customers.php index 753af4e7a..7080a184f 100644 --- a/app/Http/Controllers/Incomes/Customers.php +++ b/app/Http/Controllers/Incomes/Customers.php @@ -187,4 +187,11 @@ class Customers extends Controller return response()->json($customer); } + + public function customer(Request $request) + { + $customer = Customer::create($request->all()); + + return response()->json($customer); + } } diff --git a/resources/lang/en-GB/bills.php b/resources/lang/en-GB/bills.php index 407cfc8e5..60a32652f 100644 --- a/resources/lang/en-GB/bills.php +++ b/resources/lang/en-GB/bills.php @@ -27,6 +27,8 @@ return [ 'download_pdf' => 'Download PDF', 'send_mail' => 'Send Email', + 'create_vendor' => 'Vendor Create', + 'status' => [ 'draft' => 'Draft', 'received' => 'Received', diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index 7f52a170f..3aa7bc692 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -27,6 +27,8 @@ return [ 'download_pdf' => 'Download PDF', 'send_mail' => 'Send Email', + 'create_customer' => 'Customer Create', + 'status' => [ 'draft' => 'Draft', 'sent' => 'Sent', diff --git a/resources/views/expenses/bills/create.blade.php b/resources/views/expenses/bills/create.blade.php index 006bcc5cf..8c9420498 100644 --- a/resources/views/expenses/bills/create.blade.php +++ b/resources/views/expenses/bills/create.blade.php @@ -8,7 +8,17 @@ {!! Form::open(['url' => 'expenses/bills', 'files' => true, 'role' => 'form']) !!}
- {{ Form::selectGroup('vendor_id', trans_choice('general.vendors', 1), 'user', $vendors) }} +
+ {!! Form::label('vendor_id', trans_choice('general.vendors', 1), ['class' => 'control-label']) !!} +
+
+ {!! Form::select('vendor_id', $vendors, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.vendors', 1)])])) !!} + + + +
+ {!! $errors->first('vendor_id', '

:message

') !!} +
{{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange', $currencies, setting('general.default_currency')) }} @@ -260,5 +270,112 @@ } }); } + + function createVendor() { + $('#modal-create-vendor').remove(); + + modal = ''; + + $('body').append(modal); + + $("#modal-create-vendor #currency_code").select2({ + placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}" + }); + + $('#modal-create-vendor').modal('show'); + } + + $(document).on('click', '#button-create-vendor', function (e) { + $.ajax({ + url: '{{ url("expenses/vendors/vendor") }}', + type: 'POST', + dataType: 'JSON', + data: $("#form-create-vendor").serialize(), + beforeSend: function () { + $(".form-group").removeClass("has-error"); + $(".help-block").remove(); + }, + success: function(data) { + $('#modal-create-vendor').modal('hide'); + + $("#vendor_id").append(''); + $("#vendor_id").select2('refresh'); + }, + error: function(error, textStatus, errorThrown) { + if (error.responseJSON.name) { + $("input[name='name']").parent().parent().addClass('has-error'); + $("input[name='name']").parent().after('

' + error.responseJSON.name + '

'); + } + + if (error.responseJSON.email) { + $("input[name='email']").parent().parent().addClass('has-error'); + $("input[name='email']").parent().after('

' + error.responseJSON.email + '

'); + } + + if (error.responseJSON.currency_code) { + $("select[name='currency_code']").parent().parent().addClass('has-error'); + $("select[name='currency_code']").parent().after('

' + error.responseJSON.currency_code + '

'); + } + } + }); + }); @endpush diff --git a/resources/views/incomes/invoices/create.blade.php b/resources/views/incomes/invoices/create.blade.php index 1d835d918..27c8ea6c2 100644 --- a/resources/views/incomes/invoices/create.blade.php +++ b/resources/views/incomes/invoices/create.blade.php @@ -8,7 +8,17 @@ {!! Form::open(['url' => 'incomes/invoices', 'files' => true, 'role' => 'form']) !!}
- {{ Form::selectGroup('customer_id', trans_choice('general.customers', 1), 'user', $customers) }} +
+ {!! Form::label('customer_id', trans_choice('general.customers', 1), ['class' => 'control-label']) !!} +
+
+ {!! Form::select('customer_id', $customers, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.customers', 1)])])) !!} + + + +
+ {!! $errors->first('customer_id', '

:message

') !!} +
{{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange', $currencies, setting('general.default_currency')) }} @@ -261,5 +271,112 @@ } }); } + + function createCustomer() { + $('#modal-create-customer').remove(); + + modal = ''; + + $('body').append(modal); + + $("#modal-create-customer #currency_code").select2({ + placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}" + }); + + $('#modal-create-customer').modal('show'); + } + + $(document).on('click', '#button-create-customer', function (e) { + $.ajax({ + url: '{{ url("incomes/customers/customer") }}', + type: 'POST', + dataType: 'JSON', + data: $("#form-create-customer").serialize(), + beforeSend: function () { + $(".form-group").removeClass("has-error"); + $(".help-block").remove(); + }, + success: function(data) { + $('#modal-create-customer').modal('hide'); + + $("#customer_id").append(''); + $("#customer_id").select2('refresh'); + }, + error: function(error, textStatus, errorThrown) { + if (error.responseJSON.name) { + $("input[name='name']").parent().parent().addClass('has-error'); + $("input[name='name']").parent().after('

' + error.responseJSON.name + '

'); + } + + if (error.responseJSON.email) { + $("input[name='email']").parent().parent().addClass('has-error'); + $("input[name='email']").parent().after('

' + error.responseJSON.email + '

'); + } + + if (error.responseJSON.currency_code) { + $("select[name='currency_code']").parent().parent().addClass('has-error'); + $("select[name='currency_code']").parent().after('

' + error.responseJSON.currency_code + '

'); + } + } + }); + }); @endpush diff --git a/routes/web.php b/routes/web.php index 9cfa5a740..bd6435044 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,6 +58,7 @@ Route::group(['middleware' => 'language'], function () { Route::resource('revenues', 'Incomes\Revenues'); Route::get('customers/currency', 'Incomes\Customers@currency'); Route::get('customers/{customer}/duplicate', 'Incomes\Customers@duplicate'); + Route::post('customers/customer', 'Incomes\Customers@customer'); Route::resource('customers', 'Incomes\Customers'); }); @@ -73,6 +74,7 @@ Route::group(['middleware' => 'language'], function () { Route::resource('payments', 'Expenses\Payments'); Route::get('vendors/currency', 'Expenses\Vendors@currency'); Route::get('vendors/{vendor}/duplicate', 'Expenses\Vendors@duplicate'); + Route::post('vendors/vendor', 'Expenses\Vendors@vendor'); Route::resource('vendors', 'Expenses\Vendors'); });