2022-07-29 07:47:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\BankAccountRequest;
|
|
|
|
|
use App\Http\Requests\ContactsRequest;
|
|
|
|
|
use App\Http\Resources\AccountResource;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class AccountController extends Controller
|
|
|
|
|
{
|
2022-08-03 06:52:47 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->account = request()->user()
|
|
|
|
|
->account()
|
|
|
|
|
->with('profile');
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-29 08:14:05 +00:00
|
|
|
public function account(Request $request)
|
2022-07-29 07:47:47 +00:00
|
|
|
{
|
|
|
|
|
|
2022-08-03 06:52:47 +00:00
|
|
|
if(!empty($this->account)){
|
|
|
|
|
return AccountResource::make($this->account);
|
2022-07-29 08:14:05 +00:00
|
|
|
}
|
2022-07-29 07:47:47 +00:00
|
|
|
|
2022-07-29 08:14:05 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'message'=> trans('app.account.not_found')
|
|
|
|
|
],404 );
|
2022-07-29 07:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeContacts(ContactsRequest $request){
|
|
|
|
|
|
2022-08-05 12:02:16 +00:00
|
|
|
$account = Account::with('profile')->find($request->user()->account_id);
|
2022-08-05 12:37:27 +00:00
|
|
|
|
2022-08-05 12:02:16 +00:00
|
|
|
$data['contacts'] = json_encode($request->all());
|
|
|
|
|
$account->fill($data)->save();
|
2022-08-05 12:37:27 +00:00
|
|
|
|
2022-08-08 06:26:01 +00:00
|
|
|
if(!empty($account)){
|
|
|
|
|
return AccountResource::make($account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message'=> trans('app.account.not_found')
|
|
|
|
|
],404 );
|
2022-08-03 06:52:47 +00:00
|
|
|
|
2022-07-29 07:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeBankAccount(BankAccountRequest $request){
|
|
|
|
|
|
2022-08-05 12:37:27 +00:00
|
|
|
$account = Account::with('profile')->find($request->user()->account_id);
|
|
|
|
|
|
|
|
|
|
$data['bank'] = json_encode($request->all());
|
|
|
|
|
$account->fill($data)->save();
|
|
|
|
|
|
2022-08-08 06:26:01 +00:00
|
|
|
if(!empty($account)){
|
|
|
|
|
return AccountResource::make($account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message'=> trans('app.account.not_found')
|
|
|
|
|
],404 );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storePersonal(DocumentRequest $request){
|
|
|
|
|
$account = Account::with('profile')->find($request->user()->account_id);
|
|
|
|
|
|
|
|
|
|
$data['document'] = json_encode($request->all());
|
|
|
|
|
|
|
|
|
|
$account->profile()->fill($data);
|
|
|
|
|
$account->profile()->save();
|
|
|
|
|
|
2022-08-05 12:37:27 +00:00
|
|
|
return AccountResource::make($account);
|
2022-07-29 07:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-03 06:52:47 +00:00
|
|
|
public function storeProfileInfo()
|
|
|
|
|
{
|
|
|
|
|
//Profile type using Strategy pattern
|
|
|
|
|
$type = config('account.'.$this->account->type.'.class');
|
|
|
|
|
|
|
|
|
|
$profileStrategy = new $type;
|
|
|
|
|
|
|
|
|
|
return $profileStrategy->updateProfileInfo($this->account->profile);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeProfileDocInfo(Request $request){
|
|
|
|
|
//Profile type using Strategy pattern
|
|
|
|
|
$type = config('account.'.$this->account->type.'.class');
|
|
|
|
|
|
|
|
|
|
$profileStrategy = new $type;
|
2022-07-29 07:47:47 +00:00
|
|
|
|
2022-08-03 06:52:47 +00:00
|
|
|
return $profileStrategy->updateProfileDocInfo($this->account->profile);
|
2022-07-29 07:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 06:26:01 +00:00
|
|
|
public function storeProfile(ProfileRequest $request){
|
|
|
|
|
$account = Account::with('profile')->find($request->user()->account_id);
|
|
|
|
|
|
|
|
|
|
if(!empty($account)){
|
|
|
|
|
if($account->type == 'business'){
|
|
|
|
|
$data['personal'] = $request->all();
|
|
|
|
|
$profile = new Business($data);
|
|
|
|
|
$account->profile = $profile;
|
|
|
|
|
$account->save;
|
|
|
|
|
$profile->save();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$profile = new Company($request->all());
|
|
|
|
|
$account->profile = $profile;
|
|
|
|
|
$account->save;
|
|
|
|
|
$profile->save();
|
|
|
|
|
}
|
|
|
|
|
return AccountResource::make($account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message'=> trans('app.account.not_found')
|
|
|
|
|
],404 );
|
2022-07-29 07:47:47 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|