Update supplier details to use form helpers, and added in api settings

This commit is contained in:
Deon George 2022-08-06 00:22:22 +10:00
parent ae3f97d890
commit a1fd36aa6f
7 changed files with 128 additions and 128 deletions

View File

@ -19,7 +19,7 @@ class SupplierController extends Controller
{ {
$this->middleware(['auth','wholesaler']); $this->middleware(['auth','wholesaler']);
foreach ($request->except(['_token','supplier_details','submit']) as $key => $item) foreach ($request->except(['_token','supplier_details','api_key','api_secret','submit']) as $key => $item)
$o->{$key} = $item; $o->{$key} = $item;
$o->active = (bool)$request->active; $o->active = (bool)$request->active;
@ -37,10 +37,14 @@ class SupplierController extends Controller
foreach ($request->get('supplier_details',[]) as $key => $item) foreach ($request->get('supplier_details',[]) as $key => $item)
$oo->{$key} = $item; $oo->{$key} = $item;
$oo->connections = $oo->connections->merge([
'api_key'=>$request->get('api_key'),
'api_secret'=>$request->get('api_secret'),
])->filter();
$o->detail()->save($oo); $o->detail()->save($oo);
return redirect()->back() return redirect()->back()
->with('success','Supplier saved'); ->with('success','Supplier Saved');
} }
/** /**

View File

@ -39,6 +39,8 @@ class SupplierAddEdit extends FormRequest
'supplier_details.accounts' => 'nullable|email', 'supplier_details.accounts' => 'nullable|email',
'supplier_details.support' => 'nullable|email', 'supplier_details.support' => 'nullable|email',
'supplier_details.payments' => 'nullable|string|min:3', 'supplier_details.payments' => 'nullable|string|min:3',
'api_key' => 'nullable|string|min:3',
'api_secret' => 'nullable|string|min:3',
]; ];
} }
} }

22
composer.lock generated
View File

@ -3377,11 +3377,11 @@
}, },
{ {
"name": "leenooks/laravel", "name": "leenooks/laravel",
"version": "9.2.4", "version": "9.2.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://dev.leenooks.net/leenooks/laravel", "url": "https://dev.leenooks.net/leenooks/laravel",
"reference": "61f38aefe78b4d8af630aee8c50271e50084d63c" "reference": "d494400e7eae16626016c6165acf89c18333ff1b"
}, },
"require": { "require": {
"creativeorange/gravatar": "^1.0", "creativeorange/gravatar": "^1.0",
@ -3420,7 +3420,7 @@
"laravel", "laravel",
"leenooks" "leenooks"
], ],
"time": "2022-08-03T06:32:38+00:00" "time": "2022-08-05T14:19:20+00:00"
}, },
{ {
"name": "leenooks/laravel-theme", "name": "leenooks/laravel-theme",
@ -5596,16 +5596,16 @@
}, },
{ {
"name": "stella-maris/clock", "name": "stella-maris/clock",
"version": "0.1.4", "version": "0.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://gitlab.com/stella-maris/clock.git", "url": "git@gitlab.com:stella-maris/clock.git",
"reference": "8a0a967896df4c63417385dc69328a0aec84d9cf" "reference": "447879c53ca0b2a762cdbfba5e76ccf4deca9158"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://gitlab.com/api/v4/projects/stella-maris%2Fclock/repository/archive.zip?sha=8a0a967896df4c63417385dc69328a0aec84d9cf", "url": "https://gitlab.com/api/v4/projects/stella-maris%2Fclock/repository/archive.zip?sha=447879c53ca0b2a762cdbfba5e76ccf4deca9158",
"reference": "8a0a967896df4c63417385dc69328a0aec84d9cf", "reference": "447879c53ca0b2a762cdbfba5e76ccf4deca9158",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5635,11 +5635,7 @@
"point in time", "point in time",
"psr20" "psr20"
], ],
"support": { "time": "2022-08-05T07:21:25+00:00"
"issues": "https://gitlab.com/stella-maris/clock/-/issues",
"source": "https://gitlab.com/stella-maris/clock/-/tree/0.1.4"
},
"time": "2022-04-17T14:12:26+00:00"
}, },
{ {
"name": "symfony/console", "name": "symfony/console",

View File

@ -42,4 +42,10 @@ return [
'client_secret' => env('AUTH_GOOGLE_SECRET'), 'client_secret' => env('AUTH_GOOGLE_SECRET'),
'redirect' => '/auth/google/callback', 'redirect' => '/auth/google/callback',
], ],
'supplier' => [
'crazydomain' => [
'api'=> \Dreamscape\API::class,
]
],
]; ];

View File

@ -11,7 +11,6 @@
{{ $o->name ?: 'New Supplier' }} {{ $o->name ?: 'New Supplier' }}
@endsection @endsection
@section('contentheader_description') @section('contentheader_description')
@include('adminlte::widget.status')
@endsection @endsection
@section('main-content') @section('main-content')

View File

@ -26,29 +26,17 @@
@csrf @csrf
<div class="row"> <div class="row">
<div class="col-4"> <div class="col-12 col-sm-9 col-md-6 col-xl-5">
<div class="form-group has-validation"> @include('adminlte::widget.form_select',[
<label for="name">Supplier Name</label> 'label'=>'Supplier',
<select class="form-control form-control-border" id="name" name="supplier_id"> 'icon'=>'fas fa-handshake',
<option value=""></option> 'id'=>'supplier_id',
<option value="">Add New</option> 'old'=>'supplier_id',
@foreach(\App\Models\Supplier::orderBy('active','DESC')->orderBy('name')->get()->groupBy('active') as $o) 'name'=>'supplier_id',
<optgroup label="{{ $o->first()->active ? 'Active' : 'Not Active' }}"> 'groupby'=>'active',
@foreach($o as $oo) 'options'=>\App\Models\Supplier::orderBy('active','DESC')->orderBy('name')->get()->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name,'active'=>$item->active]; }),
<option value="{{ $oo->id }}">{{ $oo->name }}</option> 'value'=>'',
@endforeach ])
</optgroup>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@error('name')
{{ $message }}
@else
Supplier Name is required.
@enderror
</span>
<span class="input-helper">Suppliers Name</span>
</div>
</div> </div>
</div> </div>
</form> </form>
@ -64,10 +52,10 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#name').select2() $('#supplier_id')
.on('change',function(item) { .on('change',function(item) {
window.location.href = '{{ url('a/supplier/details') }}'+(item.target.value ? '/'+item.target.value : ''); window.location.href = '{{ url('a/supplier/details') }}'+(item.target.value ? '/'+item.target.value : '');
}); });
}); });
</script> </script>
@endsection @append

View File

@ -1,11 +1,8 @@
<!-- $o = Supplier::class --> <!-- $o = Supplier::class -->
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<h3>Supplier Details</h3> <h3>Supplier Details @include('adminlte::widget.success_button')</h3>
<hr> <hr>
@if(session()->has('success'))
<span class="ml-3 pt-0 pb-0 pr-1 pl-1 btn btn-outline-success"><small>{{ session()->get('success') }}</small></span>
@endif
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form"> <form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
@csrf @csrf
@ -13,39 +10,35 @@
<div class="row"> <div class="row">
<div class="col-4"> <div class="col-4">
<div class="row"> <div class="row">
<!-- Supplier Name -->
<div class="col-9">
<div class="form-group has-validation">
<label for="name">Supplier Name</label>
<input type="text" class="form-control form-control-border @error('name') is-invalid @enderror" id="name" name="name" placeholder="Supplier Name" value="{{ old('name',$o->name) }}" required>
<span class="invalid-feedback" role="alert">
@error('name')
{{ $message }}
@else
Supplier Name required.
@enderror
</span>
</div>
</div>
<!-- Supplier Active --> <!-- Supplier Active -->
<div class="col-3"> <div class="col-12 col-sm-3">
<div class="form-group"> <div class="form-group left">
<div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success"> <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
<input type="checkbox" class="custom-control-input" id="active" name="active" {{ old('active',$o->active) ? 'checked' : '' }}> <input type="checkbox" class="custom-control-input" id="active" name="active" {{ old('active',$o->active) ? 'checked' : '' }}>
<label class="custom-control-label" for="active">Active</label> <label class="custom-control-label" for="active">Active</label>
</div> </div>
</div> </div>
</div> </div>
<!-- Supplier Name -->
<div class="col-12 col-sm-9">
@include('adminlte::widget.form_text',[
'label'=>'Supplier Name',
'id'=>'name',
'old'=>'name',
'name'=>'name',
'value'=>$o->name ?? '',
])
</div>
</div> </div>
<div class="row"> <div class="row">
<!-- Address Lines --> <!-- Address Lines -->
<div class="col-12"> <div class="col-12">
<div class="form-group has-validation"> <div class="form-group">
<label for="address1">Address Lines</label> <label for="address1">Address Lines</label>
<input type="text" class="form-control form-control-border @error('address1') is-invalid @enderror" id="address1" name="address1" placeholder="Address1" value="{{ old('address1',$o->address1) }}" required> <input type="text" style="border-bottom-left-radius:0;border-bottom-right-radius:0;" class="form-control @error('address1') is-invalid @enderror" id="address1" name="address1" value="{{ old('address1',$o->address1) }}">
<input type="text" class="form-control form-control-border" id="address2" name="address2" placeholder="Address2" value="{{ old('address2',$o->address2) }}"> <input type="text" style="border-top-left-radius:0;border-top-right-radius:0;" class="form-control" id="address2" name="address2" value="{{ old('address2',$o->address2) }}">
<span class="invalid-feedback" role="alert"> <span class="invalid-feedback" role="alert">
@error('address1') @error('address1')
{{ $message }} {{ $message }}
@ -60,49 +53,37 @@
<div class="row"> <div class="row">
<!-- City --> <!-- City -->
<div class="col-12"> <div class="col-12">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="city">City</label> 'label'=>'City',
<input type="text" class="form-control form-control-border @error('city') is-invalid @enderror" id="city" name="city" placeholder="City" value="{{ old('city',$o->city) }}"> 'id'=>'city',
<span class="invalid-feedback" role="alert"> 'old'=>'city',
@error('city') 'name'=>'city',
{{ $message }} 'value'=>$o->city ?? '',
@else ])
City is required.
@enderror
</span>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- State --> <!-- State -->
<div class="col-9"> <div class="col-12 col-sm-9">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="state">State</label> 'label'=>'State',
<input type="text" class="form-control form-control-border @error('state') is-invalid @enderror" id="state" name="state" placeholder="State" value="{{ old('state',$o->state) }}"> 'id'=>'state',
<span class="invalid-feedback" role="alert"> 'old'=>'state',
@error('state') 'name'=>'state',
{{ $message }} 'value'=>$o->state ?? '',
@else ])
State is required.
@enderror
</span>
</div>
</div> </div>
<!-- Postal Code --> <!-- Postal Code -->
<div class="col-3"> <div class="col-12 col-sm-3">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="postcode">Postal Code</label> 'label'=>'Post Code',
<input type="text" class="form-control form-control-border @error('postcode') is-invalid @enderror" id="postcode" name="postcode" placeholder="Postal Code" value="{{ old('postcode',$o->postcode) }}"> 'id'=>'postcode',
<span class="invalid-feedback" role="alert"> 'old'=>'postcode',
@error('postcode') 'name'=>'postcode',
{{ $message }} 'value'=>$o->postcode ?? '',
@else ])
Postcode is required.
@enderror
</span>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -111,47 +92,72 @@
<div class="row"> <div class="row">
<!-- Accounts Email --> <!-- Accounts Email -->
<div class="col-12"> <div class="col-12">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="accounts">Accounts Email</label> 'label'=>'Accounts Email',
<input type="text" class="form-control form-control-border @error('supplier_details.accounts') is-invalid @enderror" id="accounts" name="supplier_details[accounts]" placeholder="Accounts Email" value="{{ old('supplier_details.accounts',($o->detail ? $o->detail->accounts : '')) }}"> 'id'=>'supplier_details.accounts',
<span class="invalid-feedback" role="alert"> 'old'=>'supplier_details.accounts',
@error('supplier_details.accounts') 'name'=>'supplier_details[accounts]',
{{ $message }} 'value'=>($o->detail ? $o->detail->accounts : ''),
@enderror ])
</span>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- Support Email --> <!-- Support Email -->
<div class="col-12"> <div class="col-12">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="support">Support Email</label> 'label'=>'Support Email',
<input type="text" class="form-control form-control-border @error('supplier_details.support') is-invalid @enderror" id="support" name="supplier_details[support]" placeholder="Support Email" value="{{ old('supplier_details.support',($o->detail ? $o->detail->support : '')) }}"> 'id'=>'supplier_details.support',
<span class="invalid-feedback" role="alert"> 'old'=>'supplier_details.support',
@error('supplier_details.support') 'name'=>'supplier_details[support]',
{{ $message }} 'value'=>($o->detail ? $o->detail->support : ''),
@enderror ])
</span>
</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- Payment Details --> <!-- Payment Details -->
<div class="col-12"> <div class="col-12">
<div class="form-group has-validation"> @include('adminlte::widget.form_text',[
<label for="payments">Payment Details</label> 'label'=>'Payment Details',
<input type="text" class="form-control form-control-border @error('supplier_details.payments') is-invalid @enderror" id="payments" name="supplier_details[payments]" placeholder="Payment Details" value="{{ old('supplier_details.payments',($o->detail ? $o->detail->payments : '')) }}"> 'id'=>'supplier_details.payments',
<span class="invalid-feedback" role="alert"> 'old'=>'supplier_details.payments',
@error('supplier_details.payments') 'name'=>'supplier_details[payments]',
{{ $message }} 'value'=>($o->detail ? $o->detail->support : ''),
@enderror ])
</span>
</div>
</div> </div>
</div> </div>
@if($x=config('services.supplier.'.$o->name.'.api'))
<hr>
<p class="h6"><i class="fa-fw fas fa-sitemap"></i> <strong>{{ $x }}</strong></p>
<div class="row">
<!-- API Details -->
<div class="col-12">
@include('adminlte::widget.form_text',[
'label'=>'API Key',
'id'=>'api_key',
'old'=>'api_key',
'name'=>'api_key',
'value'=>($o->detail ? Arr::get($o->detail->connections,'api_key') : ''),
])
</div>
</div>
<div class="row">
<!-- API Details -->
<div class="col-12">
@include('adminlte::widget.form_text',[
'label'=>'API Secret',
'id'=>'api_secret',
'old'=>'api_secret',
'name'=>'api_secret',
'value'=>($o->detail ? Arr::get($o->detail->connections,'api_secret') : ''),
])
</div>
</div>
@endif
</div> </div>
</div> </div>
@ -161,7 +167,6 @@
<div class="form-group has-validation"> <div class="form-group has-validation">
<label for="notes">Notes</label> <label for="notes">Notes</label>
<textarea class="form-control @error('supplier_details.notes') is-invalid @enderror" id="notes" name="supplier_details[notes]" placeholder="Notes...">{{ old('supplier_details.notes',($o->detail ? $o->detail->notes : '')) }}</textarea> <textarea class="form-control @error('supplier_details.notes') is-invalid @enderror" id="notes" name="supplier_details[notes]" placeholder="Notes...">{{ old('supplier_details.notes',($o->detail ? $o->detail->notes : '')) }}</textarea>
<span class="input-helper">Notes.</span>
<span class="invalid-feedback" role="alert"> <span class="invalid-feedback" role="alert">
@error('supplier_details.notes') @error('supplier_details.notes')
{{ $message }} {{ $message }}