Skip to content

Commit

Permalink
Modal create account.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Mar 9, 2020
1 parent b243b3f commit 3dde3af
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/Http/Controllers/Modals/Accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers\Modals;

use App\Abstracts\Http\Controller;
use App\Http\Requests\Banking\Account as Request;
use App\Jobs\Banking\CreateAccount;
use App\Models\Banking\Account;
use App\Models\Setting\Currency;

class Accounts extends Controller
{
/**
* Instantiate a new controller instance.
*/
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-banking-accounts')->only(['create', 'store', 'duplicate', 'import']);
$this->middleware('permission:read-banking-accounts')->only(['index', 'show', 'edit', 'export']);
$this->middleware('permission:update-banking-accounts')->only(['update', 'enable', 'disable']);
$this->middleware('permission:delete-banking-accounts')->only('destroy');
}

/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$currencies = Currency::enabled()->pluck('name', 'code');

$currency = Currency::where('code', '=', setting('default.currency'))->first();

$html = view('modals.accounts.create', compact('currencies', 'currency'))->render();

return response()->json([
'success' => true,
'error' => false,
'message' => 'null',
'html' => $html,
]);
}

/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
{
$request['enabled'] = 1;

$response = $this->ajaxDispatch(new CreateAccount($request));

if ($response['success']) {
$response['message'] = trans('messages.success.added', ['type' => trans_choice('general.accounts', 1)]);
}

return response()->json($response);
}
}
21 changes: 21 additions & 0 deletions resources/views/modals/accounts/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{!! Form::open([
'id' => 'form-create-account',
'@submit.prevent' => 'onSubmit',
'@keydown' => 'form.errors.clear($event.target.name)',
'role' => 'form',
'class' => 'form-loading-button',
'route' => 'accounts.store',
'novalidate' => true
]) !!}
<div class="row">
{{ Form::textGroup('name', trans('general.name'), 'font') }}

{{ Form::textGroup('number', trans('accounts.number'), 'pencil-alt') }}

{{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange-alt', $currencies, setting('default.currency'), ['required' => 'required', 'change' => 'onChangeCurrency']) }}

{{ Form::moneyGroup('opening_balance', trans('accounts.opening_balance'), 'balance-scale', ['required' => 'required', 'currency' => $currency], 0.00) }}

{!! Form::hidden('enabled', '1', []) !!}
</div>
{!! Form::close() !!}
1 change: 1 addition & 0 deletions routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
});

Route::group(['as' => 'modals.', 'prefix' => 'modals'], function () {
Route::resource('accounts', 'Modals\Accounts');
Route::resource('categories', 'Modals\Categories');
Route::resource('currencies', 'Modals\Currencies');
Route::resource('customers', 'Modals\Customers');
Expand Down

0 comments on commit 3dde3af

Please sign in to comment.