2018-10-22 14:04:37 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-22 14:04:37 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-10-07 05:56:35 +02:00
|
|
|
use App\DataMapper\Analytics\AccountDeleted;
|
2020-06-05 02:24:02 +02:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-06-24 02:13:53 +02:00
|
|
|
use App\DataMapper\DefaultSettings;
|
2018-10-24 05:50:15 +02:00
|
|
|
use App\Http\Requests\Company\CreateCompanyRequest;
|
2019-06-17 02:15:42 +02:00
|
|
|
use App\Http\Requests\Company\DestroyCompanyRequest;
|
|
|
|
use App\Http\Requests\Company\EditCompanyRequest;
|
2019-06-17 01:58:33 +02:00
|
|
|
use App\Http\Requests\Company\ShowCompanyRequest;
|
2019-06-17 02:15:42 +02:00
|
|
|
use App\Http\Requests\Company\StoreCompanyRequest;
|
|
|
|
use App\Http\Requests\Company\UpdateCompanyRequest;
|
2018-10-22 14:04:37 +02:00
|
|
|
use App\Http\Requests\SignupRequest;
|
2018-10-24 05:50:15 +02:00
|
|
|
use App\Jobs\Company\CreateCompany;
|
2020-05-27 01:49:06 +02:00
|
|
|
use App\Jobs\Company\CreateCompanyPaymentTerms;
|
2020-10-20 01:01:59 +02:00
|
|
|
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
2019-06-25 07:08:07 +02:00
|
|
|
use App\Jobs\Company\CreateCompanyToken;
|
2020-04-30 13:45:47 +02:00
|
|
|
use App\Jobs\Ninja\RefundCancelledAccount;
|
2018-10-22 14:04:37 +02:00
|
|
|
use App\Jobs\RegisterNewAccount;
|
2019-10-02 23:59:27 +02:00
|
|
|
use App\Jobs\Util\UploadAvatar;
|
2019-06-26 01:44:08 +02:00
|
|
|
use App\Models\Account;
|
2019-06-17 01:58:33 +02:00
|
|
|
use App\Models\Company;
|
2019-09-17 07:42:10 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-06-17 02:15:42 +02:00
|
|
|
use App\Repositories\CompanyRepository;
|
2019-06-26 01:44:08 +02:00
|
|
|
use App\Transformers\AccountTransformer;
|
2019-06-17 01:58:33 +02:00
|
|
|
use App\Transformers\CompanyTransformer;
|
2019-09-17 07:42:10 +02:00
|
|
|
use App\Transformers\CompanyUserTransformer;
|
2020-04-30 13:45:47 +02:00
|
|
|
use App\Utils\Ninja;
|
2019-06-17 01:58:33 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-10-07 23:17:55 +02:00
|
|
|
use App\Utils\Traits\Uploadable;
|
2018-10-22 14:04:37 +02:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
|
|
use Illuminate\Http\Request;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Response;
|
2018-10-22 14:04:37 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2020-10-07 05:56:35 +02:00
|
|
|
use Turbo124\Beacon\Facades\LightLogs;
|
2018-10-22 14:04:37 +02:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class CompanyController.
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2019-03-28 22:34:58 +01:00
|
|
|
class CompanyController extends BaseController
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
|
|
|
use DispatchesJobs;
|
2019-06-17 01:58:33 +02:00
|
|
|
use MakesHash;
|
2019-10-07 23:17:55 +02:00
|
|
|
use Uploadable;
|
2019-06-17 01:58:33 +02:00
|
|
|
|
|
|
|
protected $entity_type = Company::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = CompanyTransformer::class;
|
2018-10-22 14:04:37 +02:00
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
protected $company_repo;
|
2019-06-24 02:13:53 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $forced_includes = [];
|
2019-06-24 02:13:53 +02:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* CompanyController constructor.
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CompanyRepository $company_repo
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function __construct(CompanyRepository $company_repo)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-03-28 22:34:58 +01:00
|
|
|
parent::__construct();
|
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
$this->company_repo = $company_repo;
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/companies",
|
|
|
|
* operationId="getCompanies",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Gets a list of companies",
|
|
|
|
* description="Lists companies, search and filters allow fine grained lists to be generated.
|
|
|
|
|
|
|
|
Query parameters can be added to performed more fine grained filtering of the companies, these are handled by the CompanyFilters class which defines the methods available",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A list of companies",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2019-06-21 00:15:53 +02:00
|
|
|
$companies = Company::whereAccountId(auth()->user()->company()->account->id);
|
2019-06-17 02:15:42 +02:00
|
|
|
|
|
|
|
return $this->listResponse($companies);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateCompanyRequest $request
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
|
|
|
*
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/companies/create",
|
|
|
|
* operationId="getCompaniesCreate",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Gets a new blank company object",
|
|
|
|
* description="Returns a blank object with default values",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="A blank company object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function create(CreateCompanyRequest $request)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-06-17 02:15:42 +02:00
|
|
|
$company = CompanyFactory::create(auth()->user()->company()->account->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
return $this->itemResponse($company);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreCompanyRequest $request
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/companies",
|
|
|
|
* operationId="storeCompany",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Adds a company",
|
|
|
|
* description="Adds an company to the system",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the saved company object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function store(StoreCompanyRequest $request)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-06-25 05:55:02 +02:00
|
|
|
$this->forced_includes = ['company_user'];
|
2018-10-22 14:04:37 +02:00
|
|
|
|
2019-06-20 08:20:14 +02:00
|
|
|
$company = CreateCompany::dispatchNow($request->all(), auth()->user()->company()->account);
|
2018-10-22 14:04:37 +02:00
|
|
|
|
2020-05-27 01:49:06 +02:00
|
|
|
CreateCompanyPaymentTerms::dispatchNow($company, auth()->user());
|
2020-10-20 01:01:59 +02:00
|
|
|
CreateCompanyTaskStatuses::dispatchNow($company, auth()->user());
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-11-27 10:47:59 +01:00
|
|
|
$company = $this->company_repo->save($request->all(), $company);
|
|
|
|
|
2019-10-07 23:17:55 +02:00
|
|
|
$this->uploadLogo($request->file('company_logo'), $company, $company);
|
2019-10-02 23:59:27 +02:00
|
|
|
|
2019-06-24 02:13:53 +02:00
|
|
|
auth()->user()->companies()->attach($company->id, [
|
|
|
|
'account_id' => $company->account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
2020-02-24 11:15:30 +01:00
|
|
|
'permissions' => '',
|
2020-03-03 23:46:19 +01:00
|
|
|
'settings' => null,
|
2020-06-05 02:24:02 +02:00
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
2020-02-26 04:26:07 +01:00
|
|
|
//'settings' => DefaultSettings::userSettings(),
|
2019-06-24 02:13:53 +02:00
|
|
|
]);
|
|
|
|
|
2019-06-24 13:05:47 +02:00
|
|
|
/*
|
|
|
|
* Required dependencies
|
|
|
|
*/
|
2019-06-25 05:55:02 +02:00
|
|
|
auth()->user()->setCompany($company);
|
2019-06-24 13:05:47 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create token
|
|
|
|
*/
|
2019-11-26 09:14:01 +01:00
|
|
|
$user_agent = request()->input('token_name') ?: request()->server('HTTP_USER_AGENT');
|
|
|
|
|
|
|
|
$company_token = CreateCompanyToken::dispatchNow($company, auth()->user(), $user_agent);
|
2019-06-24 13:05:47 +02:00
|
|
|
|
2019-09-17 07:42:10 +02:00
|
|
|
$this->entity_transformer = CompanyUserTransformer::class;
|
|
|
|
$this->entity_type = CompanyUser::class;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-09 07:47:12 +02:00
|
|
|
$ct = CompanyUser::whereUserId(auth()->user()->id)->whereCompanyId($company->id);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-09-17 07:42:10 +02:00
|
|
|
return $this->listResponse($ct);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowCompanyRequest $request
|
|
|
|
* @param Company $company
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/companies/{id}",
|
|
|
|
* operationId="showCompany",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Shows an company",
|
|
|
|
* description="Displays an company by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the company object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 01:58:33 +02:00
|
|
|
public function show(ShowCompanyRequest $request, Company $company)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-06-17 02:15:42 +02:00
|
|
|
return $this->itemResponse($company);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditCompanyRequest $request
|
|
|
|
* @param Company $company
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Get(
|
|
|
|
* path="/api/v1/companies/{id}/edit",
|
|
|
|
* operationId="editCompany",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Shows an company for editting",
|
|
|
|
* description="Displays an company by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the company object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function edit(EditCompanyRequest $request, Company $company)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->itemResponse($company);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateCompanyRequest $request
|
|
|
|
* @param Company $company
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Put(
|
|
|
|
* path="/api/v1/companies/{id}",
|
|
|
|
* operationId="updateCompany",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Updates an company",
|
|
|
|
* description="Handles the updating of an company by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the company object",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Company"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function update(UpdateCompanyRequest $request, Company $company)
|
2019-10-09 14:21:21 +02:00
|
|
|
{
|
2020-11-04 00:56:29 +01:00
|
|
|
|
2020-11-04 02:27:07 +01:00
|
|
|
if($request->hasFile('company_logo') || (is_array($request->input('settings')) && !array_key_exists('company_logo', $request->input('settings'))))
|
2020-11-04 00:56:29 +01:00
|
|
|
$this->removeLogo($company);
|
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
$company = $this->company_repo->save($request->all(), $company);
|
2019-10-07 06:03:01 +02:00
|
|
|
|
2019-10-10 04:24:19 +02:00
|
|
|
$company->saveSettings($request->input('settings'), $company);
|
2019-10-09 01:53:33 +02:00
|
|
|
|
2019-10-07 23:17:55 +02:00
|
|
|
$this->uploadLogo($request->file('company_logo'), $company, $company);
|
2019-10-02 23:59:27 +02:00
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
return $this->itemResponse($company);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyCompanyRequest $request
|
|
|
|
* @param Company $company
|
|
|
|
* @return Response
|
2019-10-07 06:03:01 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Delete(
|
|
|
|
* path="/api/v1/companies/{id}",
|
|
|
|
* operationId="deleteCompany",
|
|
|
|
* tags={"companies"},
|
|
|
|
* summary="Deletes a company",
|
|
|
|
* description="Handles the deletion of an company by id",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="id",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns a HTTP status",
|
2020-06-21 23:30:25 +02:00
|
|
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
2019-10-07 06:03:01 +02:00
|
|
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
|
|
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=422,
|
|
|
|
* description="Validation error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-10-07 06:03:01 +02:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-06-17 02:15:42 +02:00
|
|
|
public function destroy(DestroyCompanyRequest $request, Company $company)
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2020-03-08 06:59:06 +01:00
|
|
|
$company_count = $company->account->companies->count();
|
2020-04-30 13:45:47 +02:00
|
|
|
$account = $company->account;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($company_count == 1) {
|
2020-03-08 06:59:06 +01:00
|
|
|
$company->company_users->each(function ($company_user) {
|
|
|
|
$company_user->user->forceDelete();
|
|
|
|
});
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (Ninja::isHosted()) {
|
2020-04-30 13:45:47 +02:00
|
|
|
RefundCancelledAccount::dispatchNow($account);
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-04-30 13:45:47 +02:00
|
|
|
|
|
|
|
$account->delete();
|
2020-10-07 05:56:35 +02:00
|
|
|
|
|
|
|
LightLogs::create(new AccountDeleted())
|
|
|
|
->increment()
|
|
|
|
->batch();
|
2020-10-28 11:10:49 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
} else {
|
2020-03-08 06:59:06 +01:00
|
|
|
$company_id = $company->id;
|
|
|
|
$company->delete();
|
|
|
|
|
|
|
|
//If we are deleting the default companies, we'll need to make a new company the default.
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($account->default_company_id == $company_id) {
|
2020-03-08 10:06:21 +01:00
|
|
|
$new_default_company = Company::whereAccountId($account->id)->first();
|
|
|
|
$account->default_company_id = $new_default_company->id;
|
2020-03-08 06:59:06 +01:00
|
|
|
$account->save();
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 23:44:25 +02:00
|
|
|
|
2020-03-08 06:59:06 +01:00
|
|
|
return response()->json(['message' => 'success'], 200);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
}
|