Skip to content

Commit

Permalink
Wizard Currencies step finished
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Oct 25, 2018
1 parent 7037983 commit 5f00757
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 49 deletions.
102 changes: 95 additions & 7 deletions app/Http/Controllers/Wizard/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Wizard;

use Akaunting\Money\Currency as MoneyCurrency;
use App\Http\Controllers\Controller;
use App\Http\Requests\Setting\Currency as Request;
use App\Models\Banking\Account;
Expand All @@ -27,6 +28,70 @@ public function index()
return view('wizard.currencies.index', compact('currencies'));
}

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

// Prepare codes
$codes = array();
$currencies = MoneyCurrency::getCurrencies();
foreach ($currencies as $key => $item) {
// Don't show if already available
if (in_array($key, $current)) {
continue;
}

$codes[$key] = $key;
}

$html = view('wizard.currencies.create', compact('codes'))->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)
{
// Force the rate to be 1 for default currency
if ($request['default_currency']) {
$request['rate'] = '1';
}

$currency = Currency::create($request->all());

// Update default currency setting
if ($request['default_currency']) {
setting()->set('general.default_currency', $request['code']);
setting()->save();
}

$message = trans('messages.success.added', ['type' => trans_choice('general.currencies', 1)]);

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

/**
* Show the form for editing the specified resource.
*
Expand All @@ -40,7 +105,24 @@ public function edit(Currency $currency)
return redirect('/');
}

$html = view('wizard.currencies.edit', compact('currency'))->render();
// Get current currencies
$current = Currency::pluck('code')->toArray();

// Prepare codes
$codes = array();
$currencies = MoneyCurrency::getCurrencies();
foreach ($currencies as $key => $item) {
// Don't show if already available
if (($key != $currency->code) && in_array($key, $current)) {
continue;
}

$codes[$key] = $key;
}

$item = $currency;

$html = view('wizard.currencies.edit', compact('item', 'codes'))->render();

return response()->json([
'success' => true,
Expand Down Expand Up @@ -92,15 +174,21 @@ public function update(Currency $currency, Request $request)

$message = trans('messages.success.updated', ['type' => trans_choice('general.currencies', 1)]);

flash($message)->success();

return redirect('settings/currencies');
return response()->json([
'success' => true,
'error' => false,
'message' => $message,
'data' => $currency,
]);
} else {
$message = trans('messages.warning.disabled', ['name' => $currency->name, 'text' => implode(', ', $relationships)]);

flash($message)->warning();

return redirect('settings/currencies/' . $currency->id . '/edit');
return response()->json([
'success' => true,
'error' => false,
'message' => $message,
'data' => $currency,
]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/wizard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@stack('body_end')

<script type="text/javascript">
$('#wizard-skip').on('click', function() {
$('#wizard-skip, .stepwizard .btn.btn-default').on('click', function() {
$('#wizard-loading').html('<span class="wizard-loading-bar"><span class="wizard-loading-spin"><i class="fa fa-spinner fa-spin"></i></span></span>');
});
</script>
Expand Down
30 changes: 30 additions & 0 deletions resources/views/wizard/currencies/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<tr id="currency-create">
<td>
{{ Form::textGroup('name', trans('general.name'), 'id-card-o', ['required' => 'required'], null, '') }}
</td>
<td class="hidden-xs">
{{ Form::selectGroup('code', trans('currencies.code'), 'code', $codes, null, ['required' => 'required'], '') }}
</td>
<td>
{{ Form::textGroup('rate', trans('currencies.rate'), 'money', ['required' => 'required'], null, '') }}
</td>
<td class="hidden-xs">
{{ Form::radioGroup('enabled', trans('general.enabled'), trans('general.yes'), trans('general.no'), [], 'col-md-12 currency-enabled-radio-group') }}
</td>
<td class="text-center">
{!! Form::button('<span class="fa fa-save"></span>', ['type' => 'button', 'class' => 'btn btn-success currency-submit', 'data-loading-text' => trans('general.loading'), 'data-href' => url('wizard/currencies/'), 'style' => 'padding: 9px 14px; margin-top: 10px;']) !!}
</td>
<td class="hidden">
{{ Form::numberGroup('precision', trans('currencies.precision'), 'bullseye') }}

{{ Form::textGroup('symbol', trans('currencies.symbol.symbol'), 'font') }}

{{ Form::selectGroup('symbol_first', trans('currencies.symbol.position'), 'text-width', ['1' => trans('currencies.symbol.before'), '0' => trans('currencies.symbol.after')]) }}

{{ Form::textGroup('decimal_mark', trans('currencies.decimal_mark'), 'columns') }}

{{ Form::textGroup('thousands_separator', trans('currencies.thousands_separator'), 'columns', []) }}

{{ Form::radioGroup('default_currency', trans('currencies.default')) }}
</td>
</tr>
60 changes: 27 additions & 33 deletions resources/views/wizard/currencies/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
<tr>
<td><a href="javascript:void(0);" data-href="{{ url('wizard/currencies/' . $item->id . '/edit') }}" class="currency-edit">{{ $item->name }}</a></td>
<td class="hidden-xs">{{ $item->code }}</td>
<td>{{ $item->rate }}</td>
<tr id="currency-edit">
<td>
{{ Form::textGroup('name', trans('general.name'), 'id-card-o', [], $item->name, '') }}
</td>
<td class="hidden-xs">
@if ($item->enabled)
<span class="label label-success">{{ trans('general.enabled') }}</span>
@else
<span class="label label-danger">{{ trans('general.disabled') }}</span>
@endif
{{ Form::selectGroup('code', trans('currencies.code'), 'code', $codes, $item->code, [], '') }}
</td>
<td>
{{ Form::textGroup('rate', trans('currencies.rate'), 'money', [], $item->rate, '') }}
</td>
<td class="hidden-xs">
{{ Form::radioGroup('enabled', trans('general.enabled'), trans('general.yes'), trans('general.no'), [], 'col-md-12') }}
</td>
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" data-toggle-position="left" aria-expanded="false">
<i class="fa fa-ellipsis-h"></i>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="javascript:void(0);" data-href="{{ url('wizard/currencies/' . $item->id . '/edit') }}" class="currency-edit">{{ trans('general.edit') }}</a></li>
@if ($item->enabled)
<li><a href="javascript:void(0);" data-href="{{ url('wizard/currencies/' . $item->id . '/disable') }}" class="currency-disable">{{ trans('general.disable') }}</a></li>
@else
<li><a href="javascript:void(0);" data-href="{{ url('wizard/currencies/' . $item->id . '/enable') }}" class="currency-enable">{{ trans('general.enable') }}</a></li>
@endif
@permission('delete-settings-currencies')
<li class="divider"></li>
<li>
{!! Form::button(trans('general.delete'), array(
'type' => 'button',
'class' => 'delete-link',
'title' => trans('general.delete'),
'onclick' => 'confirmDelete("' . '#currencies-' . $item->id . '", "' . trans_choice('general.currencies', 2) . '", "' . trans('general.delete_confirm', ['name' => '<strong>' . $item->name . '</strong>', 'type' => mb_strtolower(trans_choice('general.currencies', 1))]) . '", "' . trans('general.cancel') . '", "' . trans('general.delete') . '")'
)) !!}
</li>
@endpermission
</ul>
</div>
{!! Form::button('<span class="fa fa-save"></span>', ['type' => 'button', 'class' => 'btn btn-success currency-updated', 'data-loading-text' => trans('general.loading'), 'data-href' => url('wizard/currencies/' . $item->id), 'style' => 'padding: 9px 14px; margin-top: 10px;']) !!}
</td>
<td class="hidden">
{{ Form::numberGroup('precision', trans('currencies.precision'), 'bullseye', [], $item->precision) }}

{{ Form::textGroup('symbol', trans('currencies.symbol.symbol'), 'font', [], $item->symbol, '') }}

{{ Form::selectGroup('symbol_first', trans('currencies.symbol.position'), 'text-width', ['1' => trans('currencies.symbol.before'), '0' => trans('currencies.symbol.after')], $item->symbol_first) }}

{{ Form::textGroup('decimal_mark', trans('currencies.decimal_mark'), 'columns', [], $item->decimal_mark, '') }}

{{ Form::textGroup('thousands_separator', trans('currencies.thousands_separator'), 'columns', [], $item->thousands_separator) }}

{{ Form::radioGroup('default_currency', trans('currencies.default')) }}

{{ Form::hidden('id', $item->id) }}
</td>
</tr>

0 comments on commit 5f00757

Please sign in to comment.