account API fixed
This commit is contained in:
parent
e56c8577c4
commit
6054438d59
|
|
@ -6,10 +6,12 @@
|
|||
use App\Http\Requests\BankAccountRequest;
|
||||
use App\Http\Requests\ContactsRequest;
|
||||
use App\Http\Resources\AccountResource;
|
||||
use App\Models\Account;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @OA\GET(
|
||||
* path="/api/account",
|
||||
|
|
@ -28,11 +30,11 @@ class AccountController extends Controller
|
|||
* )
|
||||
* )
|
||||
*/
|
||||
public function account(Request $request)
|
||||
{
|
||||
$account = $request->user()
|
||||
->account()
|
||||
->with('profile');
|
||||
public function account(Request $request){
|
||||
|
||||
$account = Account::with('profile')->find($request->user()->account_id);
|
||||
|
||||
//return $account;
|
||||
|
||||
if(!empty($account)){
|
||||
return AccountResource::make($account);
|
||||
|
|
|
|||
|
|
@ -40,27 +40,22 @@ public function setup()
|
|||
*/
|
||||
protected function setupListOperation()
|
||||
{
|
||||
CRUD::column('type');
|
||||
CRUD::column('vat');
|
||||
CRUD::column('country_id');
|
||||
CRUD::column('legalization_number');
|
||||
|
||||
|
||||
// dropdown filter
|
||||
$this->crud->addFilter([
|
||||
'name' => 'status',
|
||||
'type' => 'dropdown',
|
||||
'label' => 'Account type'
|
||||
], [
|
||||
'company' => 'Company',
|
||||
'business' => 'Business'
|
||||
], function($value) { // if the filter is active
|
||||
$this->crud->addClause('where', 'type', $value);
|
||||
});
|
||||
/**
|
||||
* Columns can be defined using the fluent syntax or array syntax:
|
||||
* - CRUD::column('price')->type('number');
|
||||
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
|
||||
*/
|
||||
// $this->crud->addFilter([
|
||||
// 'name' => 'status',
|
||||
// 'type' => 'dropdown',
|
||||
// 'label' => 'Account type'
|
||||
// ], [
|
||||
// 'company' => 'Company',
|
||||
// 'business' => 'Business'
|
||||
// ], function($value) { // if the filter is active
|
||||
// $this->crud->addClause('where', 'type', $value);
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Business;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Symfony\Component\HttpKernel\Profiler\Profile;
|
||||
|
||||
class AccountResource extends JsonResource
|
||||
{
|
||||
|
|
@ -18,15 +20,17 @@ public function toArray($request)
|
|||
'id' => $this->id,
|
||||
'bank_account' => $this->bank_account,
|
||||
'contacts' => $this->contacts,
|
||||
'account_type' => $this->account_type,
|
||||
'account_type' => $this->type,
|
||||
'profile' => $this->profile()
|
||||
];
|
||||
}
|
||||
|
||||
private function profile() : JsonResource
|
||||
{
|
||||
$type = config('account.'.$this->account_type.'.resource');
|
||||
|
||||
return $type::make($this->profile);
|
||||
if($this->profile){
|
||||
$type = config('account.'.$this->type.'.resource');
|
||||
return $type::make($this->profile);
|
||||
}
|
||||
return new JsonResource([]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ class BusinessProfileResource extends JsonResource
|
|||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
return [
|
||||
'personal' => $this->personal,
|
||||
'document' => $this->document,
|
||||
'job' => $this->job
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Account extends Model
|
|||
// public $timestamps = false;
|
||||
protected $guarded = ['id'];
|
||||
protected $fillable = [
|
||||
'contacts', 'bank', 'vat', 'country_id', 'legalization_number','type'
|
||||
'contacts', 'bank', 'vat', 'country_id', 'legalization_number', 'type',
|
||||
];
|
||||
protected $casts = [
|
||||
'contacts' => 'array',
|
||||
|
|
@ -57,6 +57,10 @@ public function application(){
|
|||
return $this->hasOne(Application::class);
|
||||
}
|
||||
|
||||
public function clients(){
|
||||
return $this->hasMany(Client::class);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| SCOPES
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Client extends Authenticatable
|
|||
// public $timestamps = false;
|
||||
protected $guarded = ['id'];
|
||||
protected $fillable = [
|
||||
'firstname', 'lastname', 'email', 'password', 'is_verified','verification_token', 'is_suspended'
|
||||
'firstname', 'lastname', 'email', 'password', 'is_verified','verification_token', 'is_suspended', 'account_id'
|
||||
];
|
||||
protected $hidden = [
|
||||
'password',
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
return [
|
||||
'business' => [
|
||||
'class' => App\AccountTypes\BusinessAccount::class,
|
||||
'resources' => App\Http\Resources\BusinessProfileResource::class
|
||||
'resource' => App\Http\Resources\BusinessProfileResource::class
|
||||
],
|
||||
'company' => [
|
||||
'class' => App\AccountTypes\CompanyAccount::class,
|
||||
'resources' => App\Http\Resources\CompanyProfileResource::class
|
||||
'resource' => App\Http\Resources\CompanyProfileResource::class
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
<!-- select -->
|
||||
@php
|
||||
$current_value = old_empty_or_null($field['name'], '') ?? $field['value'] ?? $field['default'] ?? '';
|
||||
$entity_model = $crud->getRelationModel($field['entity'], - 1);
|
||||
$field['allows_null'] = $field['allows_null'] ?? $entity_model::isColumnNullable($field['name']);
|
||||
|
||||
//if it's part of a relationship here we have the full related model, we want the key.
|
||||
if (is_object($current_value) && is_subclass_of(get_class($current_value), 'Illuminate\Database\Eloquent\Model') ) {
|
||||
$current_value = $current_value->getKey();
|
||||
}
|
||||
|
||||
if (!isset($field['options'])) {
|
||||
$options = $field['model']::all();
|
||||
} else {
|
||||
$options = call_user_func($field['options'], $field['model']::query());
|
||||
}
|
||||
@endphp
|
||||
|
||||
@include('crud::fields.inc.wrapper_start')
|
||||
|
||||
<label>{!! $field['label'] !!}</label>
|
||||
@include('crud::fields.inc.translatable_icon')
|
||||
|
||||
<select
|
||||
name="{{ $field['name'] }}"
|
||||
@include('crud::fields.inc.attributes')
|
||||
>
|
||||
|
||||
@if ($field['allows_null'])
|
||||
<option value="">-</option>
|
||||
@endif
|
||||
|
||||
@if (count($options))
|
||||
@foreach ($options as $connected_entity_entry)
|
||||
@if($current_value == $connected_entity_entry->getKey())
|
||||
<option value="{{ $connected_entity_entry->getKey() }}" selected>{{ $connected_entity_entry->{$field['attribute']} }}</option>
|
||||
@else
|
||||
<option value="{{ $connected_entity_entry->getKey() }}">{{ $connected_entity_entry->{$field['attribute']} }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
|
||||
{{-- HINT --}}
|
||||
@if (isset($field['hint']))
|
||||
<p class="help-block">{!! $field['hint'] !!}</p>
|
||||
@endif
|
||||
|
||||
@include('crud::fields.inc.wrapper_end')
|
||||
|
|
@ -0,0 +1,227 @@
|
|||
<!-- Backpack Table Field Type -->
|
||||
|
||||
<?php
|
||||
$max = isset($field['max']) && (int) $field['max'] > 0 ? $field['max'] : -1;
|
||||
$min = isset($field['min']) && (int) $field['min'] > 0 ? $field['min'] : -1;
|
||||
$item_name = strtolower(isset($field['entity_singular']) && ! empty($field['entity_singular']) ? $field['entity_singular'] : $field['label']);
|
||||
|
||||
$items = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '';
|
||||
|
||||
// make sure no matter the attribute casting
|
||||
// the $items variable contains a properly defined JSON string
|
||||
if (is_array($items)) {
|
||||
if (count($items)) {
|
||||
$items = json_encode($items);
|
||||
} else {
|
||||
$items = '[]';
|
||||
}
|
||||
} elseif (is_string($items) && ! is_array(json_decode($items))) {
|
||||
$items = '[]';
|
||||
}
|
||||
|
||||
// make sure columns are defined
|
||||
if (! isset($field['columns'])) {
|
||||
$field['columns'] = ['value' => 'Value'];
|
||||
}
|
||||
|
||||
$field['wrapper'] = $field['wrapper'] ?? $field['wrapperAttributes'] ?? [];
|
||||
$field['wrapper']['data-field-type'] = 'table';
|
||||
$field['wrapper']['data-field-name'] = $field['name'];
|
||||
?>
|
||||
@include('crud::fields.inc.wrapper_start')
|
||||
|
||||
<label>{!! $field['label'] !!}</label>
|
||||
@include('crud::fields.inc.translatable_icon')
|
||||
|
||||
<input class="array-json"
|
||||
type="hidden"
|
||||
data-init-function="bpFieldInitTableElement"
|
||||
name="{{ $field['name'] }}"
|
||||
value="{{ $items }}"
|
||||
data-max="{{$max}}"
|
||||
data-min="{{$min}}"
|
||||
data-maxErrorTitle="{{trans('backpack::crud.table_cant_add', ['entity' => $item_name])}}"
|
||||
data-maxErrorMessage="{{trans('backpack::crud.table_max_reached', ['max' => $max])}}">
|
||||
|
||||
<div class="array-container form-group">
|
||||
|
||||
<table class="table table-sm table-striped m-b-0">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach( $field['columns'] as $column )
|
||||
<th style="font-weight: 600!important;">
|
||||
{{ $column }}
|
||||
</th>
|
||||
@endforeach
|
||||
<th class="text-center"> {{-- <i class="la la-sort"></i> --}} </th>
|
||||
<th class="text-center"> {{-- <i class="la la-trash"></i> --}} </th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="table-striped items sortableOptions">
|
||||
|
||||
<tr class="array-row clonable" style="display: none;">
|
||||
@foreach( $field['columns'] as $column => $label)
|
||||
<td>
|
||||
<input class="form-control form-control-sm" type="text" data-cell-name="item.{{ $column }}">
|
||||
</td>
|
||||
@endforeach
|
||||
<td>
|
||||
<span class="btn btn-sm btn-light sort-handle pull-right"><span class="sr-only">sort item</span><i class="la la-sort" role="presentation" aria-hidden="true"></i></span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-light removeItem" type="button"><span class="sr-only">delete item</span><i class="la la-trash" role="presentation" aria-hidden="true"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<div class="array-controls btn-group m-t-10">
|
||||
<button class="btn btn-sm btn-light" type="button" data-button-type="addItem"><i class="la la-plus"></i> {{trans('backpack::crud.add')}} {{ $item_name }}</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- HINT --}}
|
||||
@if (isset($field['hint']))
|
||||
<p class="help-block">{!! $field['hint'] !!}</p>
|
||||
@endif
|
||||
@include('crud::fields.inc.wrapper_end')
|
||||
|
||||
{{-- ########################################## --}}
|
||||
{{-- Extra CSS and JS for this particular field --}}
|
||||
{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
|
||||
@if ($crud->fieldTypeNotLoaded($field))
|
||||
@php
|
||||
$crud->markFieldTypeAsLoaded($field);
|
||||
@endphp
|
||||
|
||||
{{-- FIELD JS - will be loaded in the after_scripts section --}}
|
||||
@push('crud_fields_scripts')
|
||||
{{-- YOUR JS HERE --}}
|
||||
<script type="text/javascript" src="{{ asset('packages/jquery-ui-dist/jquery-ui.min.js') }}"></script>
|
||||
|
||||
<script>
|
||||
function bpFieldInitTableElement(element) {
|
||||
var $tableWrapper = element.parent('[data-field-type=table]');
|
||||
var $rows = (element.attr('value') != '') ? $.parseJSON(element.attr('value')) : '';
|
||||
var $max = element.attr('data-max');
|
||||
var $min = element.attr('data-min');
|
||||
var $maxErrorTitle = element.attr('data-maxErrorTitle');
|
||||
var $maxErrorMessage = element.attr('data-maxErrorMessage');
|
||||
|
||||
|
||||
// add rows with the information from the database
|
||||
if($rows != '[]') {
|
||||
$.each($rows, function(key) {
|
||||
|
||||
addItem();
|
||||
|
||||
$.each(this, function(column , value) {
|
||||
$tableWrapper.find('tbody tr:last').find('input[data-cell-name="item.' + column + '"]').val(value);
|
||||
});
|
||||
|
||||
// if it's the last row, update the JSON
|
||||
if ($rows.length == key+1) {
|
||||
updateTableFieldJson();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// add minimum rows if needed
|
||||
var itemCount = $tableWrapper.find('tbody tr').not('.clonable').length;
|
||||
if($min > 0 && itemCount < $min) {
|
||||
$rowsToAdd = Number($min) - Number(itemCount);
|
||||
|
||||
for(var i = 0; i < $rowsToAdd; i++){
|
||||
addItem();
|
||||
}
|
||||
}
|
||||
|
||||
$tableWrapper.find('.sortableOptions').sortable({
|
||||
handle: '.sort-handle',
|
||||
axis: 'y',
|
||||
helper: function(e, ui) {
|
||||
ui.children().each(function() {
|
||||
$(this).width($(this).width());
|
||||
});
|
||||
return ui;
|
||||
},
|
||||
update: function( event, ui ) {
|
||||
updateTableFieldJson();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$tableWrapper.find('[data-button-type=addItem]').click(function() {
|
||||
if($max > -1) {
|
||||
var totalRows = $tableWrapper.find('tbody tr').not('.clonable').length;
|
||||
|
||||
if(totalRows < $max) {
|
||||
addItem();
|
||||
updateTableFieldJson();
|
||||
} else {
|
||||
new Noty({
|
||||
type: "warning",
|
||||
text: "<strong>"+$maxErrorTitle+"</strong><br>"+$maxErrorMessage
|
||||
}).show();
|
||||
}
|
||||
} else {
|
||||
addItem();
|
||||
updateTableFieldJson();
|
||||
}
|
||||
});
|
||||
|
||||
function addItem() {
|
||||
$tableWrapper.find('tbody').append($tableWrapper.find('tbody .clonable').clone().show().removeClass('clonable'));
|
||||
}
|
||||
|
||||
$tableWrapper.on('click', '.removeItem', function() {
|
||||
var totalRows = $tableWrapper.find('tbody tr').not('.clonable').length;
|
||||
if (totalRows > $min) {
|
||||
$(this).closest('tr').remove();
|
||||
updateTableFieldJson();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$tableWrapper.find('tbody').on('keyup', function() {
|
||||
updateTableFieldJson();
|
||||
});
|
||||
|
||||
|
||||
function updateTableFieldJson() {
|
||||
var $rows = $tableWrapper.find('tbody tr').not('.clonable');
|
||||
var $hiddenField = $tableWrapper.find('input.array-json');
|
||||
|
||||
var json = '[';
|
||||
var otArr = [];
|
||||
var tbl2 = $rows.each(function(i) {
|
||||
x = $(this).children().closest('td').find('input');
|
||||
var itArr = [];
|
||||
x.each(function() {
|
||||
if(this.value.length > 0) {
|
||||
var key = $(this).attr('data-cell-name').replace('item.','');
|
||||
itArr.push('"' + key + '":' + JSON.stringify(this.value));
|
||||
}
|
||||
});
|
||||
otArr.push('{' + itArr.join(',') + '}');
|
||||
})
|
||||
json += otArr.join(",") + ']';
|
||||
|
||||
var totalRows = $rows.length;
|
||||
|
||||
$hiddenField.val( totalRows ? json : null );
|
||||
}
|
||||
|
||||
// on page load, make sure the input has the old values
|
||||
updateTableFieldJson();
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
@endif
|
||||
{{-- End of Extra CSS and JS --}}
|
||||
{{-- ########################################## --}}
|
||||
Loading…
Reference in New Issue