2019-10-05 00:58:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-10-05 00:58:51 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-10-05 00:58:51 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Factory\GroupSettingFactory;
|
2023-04-29 01:44:34 +02:00
|
|
|
use App\Filters\GroupSettingFilters;
|
2019-10-05 00:58:51 +02:00
|
|
|
use App\Http\Requests\GroupSetting\CreateGroupSettingRequest;
|
|
|
|
use App\Http\Requests\GroupSetting\DestroyGroupSettingRequest;
|
|
|
|
use App\Http\Requests\GroupSetting\EditGroupSettingRequest;
|
|
|
|
use App\Http\Requests\GroupSetting\ShowGroupSettingRequest;
|
|
|
|
use App\Http\Requests\GroupSetting\StoreGroupSettingRequest;
|
|
|
|
use App\Http\Requests\GroupSetting\UpdateGroupSettingRequest;
|
2021-10-19 22:58:14 +02:00
|
|
|
use App\Http\Requests\GroupSetting\UploadGroupSettingRequest;
|
|
|
|
use App\Models\Account;
|
2019-10-05 00:58:51 +02:00
|
|
|
use App\Models\GroupSetting;
|
|
|
|
use App\Repositories\GroupSettingRepository;
|
|
|
|
use App\Transformers\GroupSettingTransformer;
|
2020-08-02 08:31:55 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-01-18 12:06:26 +01:00
|
|
|
use App\Utils\Traits\SavesDocuments;
|
2019-10-07 23:17:55 +02:00
|
|
|
use App\Utils\Traits\Uploadable;
|
2019-10-05 00:58:51 +02:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Response;
|
2019-10-05 00:58:51 +02:00
|
|
|
|
|
|
|
class GroupSettingController extends BaseController
|
|
|
|
{
|
|
|
|
use DispatchesJobs;
|
2019-10-07 23:17:55 +02:00
|
|
|
use Uploadable;
|
2020-08-02 08:31:55 +02:00
|
|
|
use MakesHash;
|
2021-01-18 12:06:26 +01:00
|
|
|
use SavesDocuments;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-05 00:58:51 +02:00
|
|
|
protected $entity_type = GroupSetting::class;
|
|
|
|
|
|
|
|
protected $entity_transformer = GroupSettingTransformer::class;
|
|
|
|
|
|
|
|
protected $group_setting_repo;
|
|
|
|
|
|
|
|
public function __construct(GroupSettingRepository $group_setting_repo)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->group_setting_repo = $group_setting_repo;
|
|
|
|
}
|
|
|
|
|
2023-04-29 01:56:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @param GroupSettingFilters $filters
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*/
|
2023-04-29 01:44:34 +02:00
|
|
|
public function index(GroupSettingFilters $filters)
|
2019-10-05 00:58:51 +02:00
|
|
|
{
|
2023-04-29 01:44:34 +02:00
|
|
|
$group_settings = GroupSetting::filter($filters);
|
2019-10-05 00:58:51 +02:00
|
|
|
|
|
|
|
return $this->listResponse($group_settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param CreateGroupSettingRequest $request
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2023-04-29 01:56:27 +02:00
|
|
|
*/
|
2019-10-05 00:58:51 +02:00
|
|
|
public function create(CreateGroupSettingRequest $request)
|
|
|
|
{
|
2023-04-29 01:56:27 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$group_setting = GroupSettingFactory::create($user->company()->id, $user->id);
|
2019-10-05 00:58:51 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($group_setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param StoreGroupSettingRequest $request
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
public function store(StoreGroupSettingRequest $request)
|
|
|
|
{
|
2023-04-29 01:56:27 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$group_setting = GroupSettingFactory::create($user->company()->id, $user->id);
|
2019-10-05 00:58:51 +02:00
|
|
|
|
|
|
|
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-07 23:17:55 +02:00
|
|
|
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
|
|
|
|
2019-10-05 00:58:51 +02:00
|
|
|
return $this->itemResponse($group_setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param ShowGroupSettingRequest $request
|
|
|
|
* @param GroupSetting $group_setting
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
public function show(ShowGroupSettingRequest $request, GroupSetting $group_setting)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($group_setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param EditGroupSettingRequest $request
|
|
|
|
* @param GroupSetting $group_setting
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
public function edit(EditGroupSettingRequest $request, GroupSetting $group_setting)
|
|
|
|
{
|
|
|
|
return $this->itemResponse($group_setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param UpdateGroupSettingRequest $request
|
|
|
|
* @param GroupSetting $group_setting
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
public function update(UpdateGroupSettingRequest $request, GroupSetting $group_setting)
|
|
|
|
{
|
2023-08-24 00:56:20 +02:00
|
|
|
/** Need this to prevent settings from being overwritten */
|
2023-10-26 04:57:44 +02:00
|
|
|
if(!$request->file('company_logo')) {
|
2023-08-24 00:56:20 +02:00
|
|
|
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-10-07 23:17:55 +02:00
|
|
|
$this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($request->has('documents')) {
|
2023-08-20 06:05:26 +02:00
|
|
|
$this->saveDocuments($request->input('documents'), $group_setting, $request->input('is_public', true));
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-01-18 12:06:26 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->itemResponse($group_setting);
|
2019-10-05 00:58:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param DestroyGroupSettingRequest $request
|
|
|
|
* @param GroupSetting $group_setting
|
|
|
|
* @return Response
|
2019-10-07 06:13:50 +02:00
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Exception
|
2019-10-05 00:58:51 +02:00
|
|
|
*/
|
|
|
|
public function destroy(DestroyGroupSettingRequest $request, GroupSetting $group_setting)
|
|
|
|
{
|
|
|
|
$group_setting->delete();
|
|
|
|
|
2021-01-17 05:28:03 +01:00
|
|
|
return $this->itemResponse($group_setting->fresh());
|
2019-10-05 00:58:51 +02:00
|
|
|
}
|
2020-06-24 01:39:49 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Perform bulk actions on the list view.
|
2020-06-24 01:39:49 +02:00
|
|
|
*
|
2023-04-29 01:56:27 +02:00
|
|
|
* @return Response
|
2020-06-24 01:39:49 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = request()->input('action');
|
|
|
|
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
2023-04-29 13:10:26 +02:00
|
|
|
$group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company();
|
2020-06-24 01:39:49 +02:00
|
|
|
|
2023-04-29 13:10:26 +02:00
|
|
|
if ($group_settings->count() == 0) {
|
2021-01-24 23:24:13 +01:00
|
|
|
return response()->json(['message' => ctrans('texts.no_group_settings_found')]);
|
2020-06-24 01:39:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-29 01:56:27 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
2020-06-24 01:39:49 +02:00
|
|
|
/*
|
|
|
|
* Send the other actions to the switch
|
|
|
|
*/
|
2023-04-29 13:10:26 +02:00
|
|
|
$group_settings->cursor()->each(function ($group, $key) use ($action, $user) {
|
2023-04-29 01:56:27 +02:00
|
|
|
if ($user->can('edit', $group)) {
|
2020-06-24 01:39:49 +02:00
|
|
|
$this->group_setting_repo->{$action}($group);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Need to understand which permission are required for the given bulk action ie. view / edit */
|
|
|
|
|
|
|
|
return $this->listResponse(GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
|
|
|
}
|
2021-10-19 22:58:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param UploadGroupSettingRequest $request
|
|
|
|
* @param GroupSetting $group_setting
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function upload(UploadGroupSettingRequest $request, GroupSetting $group_setting)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $this->checkFeature(Account::FEATURE_DOCUMENTS)) {
|
2021-10-19 22:58:14 +02:00
|
|
|
return $this->featureFailure();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->has('documents')) {
|
2023-08-20 06:05:26 +02:00
|
|
|
$this->saveDocuments($request->file('documents'), $group_setting, $request->input('is_public', true));
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-10-19 22:58:14 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($group_setting->fresh());
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2019-10-05 00:58:51 +02:00
|
|
|
}
|