refs #443 Payment create page new vendor and category

This commit is contained in:
cuneytsenturk 2018-08-15 18:19:38 +03:00
parent 41f54e64f6
commit 17eda360d5
4 changed files with 108 additions and 182 deletions

View File

@ -27,7 +27,7 @@ class Categories extends Controller
*/
public function create()
{
$html = view('modals.categories.create')->render();
$html = view('modals.categories.create', compact('currencies'))->render();
return response()->json([
'success' => true,

View File

@ -15,6 +15,7 @@
{{ Form::textGroup('amount', trans('general.amount'), 'money', ['required' => 'required', 'autofocus' => 'autofocus']) }}
@stack('account_id_input_start')
<div class="form-group col-md-6 form-small">
{!! Form::label('account_id', trans_choice('general.accounts', 1), ['class' => 'control-label']) !!}
<div class="input-group">
@ -25,31 +26,36 @@
</div>
</div>
</div>
@stack('account_id_input_end')
@stack('vendor_id_input_start')
<div class="form-group col-md-6">
{!! Form::label('vendor_id', trans_choice('general.vendors', 1), ['class' => 'control-label']) !!}
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
{!! Form::select('vendor_id', $vendors, null, array_merge(['id' => 'vendor_id', 'class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.vendors', 1)])])) !!}
<span class="input-group-btn">
<button type="button" onclick="createVendor();" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
<button type="button" id="button-vendor" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
</span>
</div>
</div>
@stack('vendor_id_input_end')
{{ Form::textareaGroup('description', trans('general.description')) }}
@stack('category_id_input_start')
<div class="form-group col-md-6 required {{ $errors->has('category_id') ? 'has-error' : ''}}">
{!! Form::label('category_id', trans_choice('general.categories', 1), ['class' => 'control-label']) !!}
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-folder-open-o"></i></div>
{!! Form::select('category_id', $categories, null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.categories', 1)])])) !!}
<div class="input-group-btn">
<button type="button" onclick="createCategory();" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
<button type="button" id="button-category" class="btn btn-default btn-icon"><i class="fa fa-plus"></i></button>
</div>
</div>
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div>
@stack('category_id_input_end')
{{ Form::recurring('create') }}
@ -166,198 +172,31 @@
});
});
function createVendor() {
$(document).on('click', '#button-vendor', function (e) {
$('#modal-create-vendor').remove();
modal = '<div class="modal fade" id="modal-create-vendor" style="display: none;">';
modal += ' <div class="modal-dialog modal-lg">';
modal += ' <div class="modal-content">';
modal += ' <div class="modal-header">';
modal += ' <h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.vendors', 1)]) }}</h4>';
modal += ' </div>';
modal += ' <div class="modal-body">';
modal += ' {!! Form::open(['id' => 'form-create-vendor', 'role' => 'form']) !!}';
modal += ' <div class="row">';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="name" class="control-label">{{ trans('general.name') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6">';
modal += ' <label for="email" class="control-label">{{ trans('general.email') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-envelope"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.email') }}" name="email" type="text" id="email">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6">';
modal += ' <label for="tax_number" class="control-label">{{ trans('general.tax_number') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.tax_number') }}" name="tax_number" type="text" id="tax_number">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="email" class="control-label">{{ trans_choice('general.currencies', 1) }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-exchange"></i></div>';
modal += ' <select class="form-control" required="required" id="vendor_currency_code" name="currency_code">';
modal += ' <option value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}</option>';
@foreach($currencies as $currency_code => $currency_name)
modal += ' <option value="{{ $currency_code }}" {{ (setting('general.default_currency') == $currency_code) ? 'selected' : '' }}>{{ $currency_name }}</option>';
@endforeach
modal += ' </select>';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-12">';
modal += ' <label for="address" class="control-label">{{ trans('general.address') }}</label>';
modal += ' <textarea class="form-control" placeholder="{{ trans('general.address') }}" rows="3" name="address" cols="50" id="address"></textarea>';
modal += ' </div>';
modal += ' {!! Form::hidden('enabled', '1', []) !!}';
modal += ' </div>';
modal += ' {!! Form::close() !!}';
modal += ' </div>';
modal += ' <div class="modal-footer">';
modal += ' <div class="pull-left">';
modal += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-vendor', 'class' => 'btn btn-success']) !!}';
modal += ' <button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</button>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += '</div>';
$('body').append(modal);
$("#modal-create-vendor #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) {
$('#modal-create-vendor .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
$.ajax({
url: '{{ url("expenses/vendors/vendor") }}',
type: 'POST',
url: '{{ url("modals/vendors/create") }}',
type: 'GET',
dataType: 'JSON',
data: $("#form-create-vendor").serialize(),
beforeSend: function () {
$(".form-group").removeClass("has-error");
$(".help-block").remove();
},
success: function(data) {
$('#span-loading').remove();
$('#modal-create-vendor').modal('hide');
$("#vendor_id").append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
$("#vendor_id").select2('refresh');
},
error: function(error, textStatus, errorThrown) {
$('#span-loading').remove();
if (error.responseJSON.name) {
$("#modal-create-vendor input[name='name']").parent().parent().addClass('has-error');
$("#modal-create-vendor input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
}
if (error.responseJSON.email) {
$("#modal-create-vendor input[name='email']").parent().parent().addClass('has-error');
$("#modal-create-vendor input[name='email']").parent().after('<p class="help-block">' + error.responseJSON.email + '</p>');
}
if (error.responseJSON.currency_code) {
$("#modal-create-vendor select[name='currency_code']").parent().parent().addClass('has-error');
$("#modal-create-vendor select[name='currency_code']").parent().after('<p class="help-block">' + error.responseJSON.currency_code + '</p>');
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});
});
function createCategory() {
$(document).on('click', '#button-category', function (e) {
$('#modal-create-category').remove();
modal = '<div class="modal fade" id="modal-create-category" style="display: none;">';
modal += ' <div class="modal-dialog modal-lg">';
modal += ' <div class="modal-content">';
modal += ' <div class="modal-header">';
modal += ' <h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.categories', 1)]) }}</h4>';
modal += ' </div>';
modal += ' <div class="modal-body">';
modal += ' {!! Form::open(['id' => 'form-create-category', 'role' => 'form']) !!}';
modal += ' <div class="row">';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="name" class="control-label">{{ trans('general.name') }}</label>';
modal += ' <div class="input-group">';
modal += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
modal += ' <input class="form-control" placeholder="{{ trans('general.name') }}" required="required" name="name" type="text" id="name">';
modal += ' </div>';
modal += ' </div>';
modal += ' <div class="form-group col-md-6 required">';
modal += ' <label for="color" class="control-label">{{ trans('general.color') }}</label>';
modal += ' <div id="category-color-picker" class="input-group colorpicker-component">';
modal += ' <div class="input-group-addon"><i></i></div>';
modal += ' <input class="form-control" value="#00a65a" placeholder="{{ trans('general.color') }}" required="required" name="color" type="text" id="color">';
modal += ' </div>';
modal += ' </div>';
modal += ' {!! Form::hidden('type', 'expense', []) !!}';
modal += ' {!! Form::hidden('enabled', '1', []) !!}';
modal += ' </div>';
modal += ' {!! Form::close() !!}';
modal += ' </div>';
modal += ' <div class="modal-footer">';
modal += ' <div class="pull-left">';
modal += ' {!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-category', 'class' => 'btn btn-success']) !!}';
modal += ' <button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</button>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += ' </div>';
modal += '</div>';
$('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('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 10em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
$.ajax({
url: '{{ url("settings/categories/category") }}',
type: 'POST',
url: '{{ url("modals/categories/create") }}',
type: 'GET',
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('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
$("#category_id").select2('refresh');
},
error: function(error, textStatus, errorThrown) {
$('#span-loading').remove();
if (error.responseJSON.name) {
$("#modal-create-category input[name='name']").parent().parent().addClass('has-error');
$("#modal-create-category input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
}
if (error.responseJSON.color) {
$("#modal-create-category input[name='color']").parent().parent().addClass('has-error');
$("#modal-create-category input[name='color']").parent().after('<p class="help-block">' + error.responseJSON.color + '</p>');
success: function(json) {
if (json['success']) {
$('body').append(json['html']);
}
}
});

View File

@ -32,6 +32,7 @@
{{ Form::textGroup('amount', trans('general.amount'), 'money', ['required' => 'required', 'autofocus' => 'autofocus']) }}
@stack('account_id_input_start')
<div class="form-group col-md-6 form-small">
{!! Form::label('account_id', trans_choice('general.accounts', 1), ['class' => 'control-label']) !!}
<div class="input-group">
@ -42,6 +43,7 @@
</div>
</div>
</div>
@stack('account_id_input_end')
{{ Form::selectGroup('vendor_id', trans_choice('general.vendors', 1), 'user', $vendors, null, []) }}

View File

@ -0,0 +1,85 @@
<div class="modal fade" id="modal-create-vendor" style="display: none;">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.vendors', 1)]) }}</h4>
</div>
<div class="modal-body">
{!! Form::open(['id' => 'form-create-vendor', 'role' => 'form']) !!}
<div class="row">
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
{{ Form::textGroup('email', trans('general.email'), 'envelope', []) }}
{{ Form::textGroup('tax_number', trans('general.tax_number'), 'percent', []) }}
{{ Form::selectGroup('currency_code', trans_choice('general.currencies', 1), 'exchange', $currencies, setting('general.default_currency')) }}
{{ Form::textareaGroup('address', trans('general.address')) }}
{!! Form::hidden('enabled', '1', []) !!}
</div>
{!! Form::close() !!}
</div>
<div class="modal-footer">
<div class="pull-left">
{!! Form::button('<span class="fa fa-save"></span> &nbsp;' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-vendor', 'class' => 'btn btn-success']) !!}
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> &nbsp;{{ trans('general.cancel') }}</button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#modal-create-vendor').modal('show');
$("#modal-create-vendor #currency_code").select2({
placeholder: "{{ trans('general.form.select.field', ['field' => trans_choice('general.currencies', 1)]) }}"
});
});
$(document).on('click', '#button-create-vendor', function (e) {
$('#modal-create-vendor .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
$.ajax({
url: '{{ url("modals/vendors") }}',
type: 'POST',
dataType: 'JSON',
data: $("#form-create-vendor").serialize(),
beforeSend: function () {
$(".form-group").removeClass("has-error");
$(".help-block").remove();
},
success: function(json) {
var data = json['data'];
$('#span-loading').remove();
$('#modal-create-vendor').modal('hide');
$("#vendor_id").append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
$("#vendor_id").select2('refresh');
},
error: function(error, textStatus, errorThrown) {
$('#span-loading').remove();
if (error.responseJSON.name) {
$("#modal-create-vendor input[name='name']").parent().parent().addClass('has-error');
$("#modal-create-vendor input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
}
if (error.responseJSON.email) {
$("#modal-create-vendor input[name='email']").parent().parent().addClass('has-error');
$("#modal-create-vendor input[name='email']").parent().after('<p class="help-block">' + error.responseJSON.email + '</p>');
}
if (error.responseJSON.currency_code) {
$("#modal-create-vendor select[name='currency_code']").parent().parent().addClass('has-error');
$("#modal-create-vendor select[name='currency_code']").parent().after('<p class="help-block">' + error.responseJSON.currency_code + '</p>');
}
}
});
});
</script>