2018-10-17 14:26:27 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-17 14:26:27 +02:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
use App\DataMapper\ClientSettings;
|
2019-02-04 13:06:19 +01:00
|
|
|
use App\Factory\ClientFactory;
|
2019-03-28 11:07:45 +01:00
|
|
|
use App\Filters\ClientFilters;
|
2019-01-21 15:06:49 +01:00
|
|
|
use App\Http\Requests\Client\CreateClientRequest;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Http\Requests\Client\DestroyClientRequest;
|
2018-11-03 02:01:40 +01:00
|
|
|
use App\Http\Requests\Client\EditClientRequest;
|
2019-01-21 15:06:49 +01:00
|
|
|
use App\Http\Requests\Client\ShowClientRequest;
|
2018-12-07 11:57:20 +01:00
|
|
|
use App\Http\Requests\Client\StoreClientRequest;
|
2018-11-10 14:24:36 +01:00
|
|
|
use App\Http\Requests\Client\UpdateClientRequest;
|
2018-12-02 11:42:06 +01:00
|
|
|
use App\Jobs\Client\StoreClient;
|
2018-11-27 07:59:16 +01:00
|
|
|
use App\Jobs\Client\UpdateClient;
|
2019-01-19 11:35:21 +01:00
|
|
|
use App\Jobs\Entity\ActionEntity;
|
2018-10-29 04:16:17 +01:00
|
|
|
use App\Models\Client;
|
2018-12-02 11:42:06 +01:00
|
|
|
use App\Models\ClientContact;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\Country;
|
2019-02-17 11:34:46 +01:00
|
|
|
use App\Models\Currency;
|
|
|
|
use App\Models\Size;
|
2019-04-23 08:19:45 +02:00
|
|
|
use App\Repositories\BaseRepository;
|
2018-11-22 12:12:41 +01:00
|
|
|
use App\Repositories\ClientRepository;
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Transformers\ClientTransformer;
|
2018-11-27 07:59:16 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-17 14:26:27 +02:00
|
|
|
use Illuminate\Http\Request;
|
2019-02-17 11:34:46 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-06-12 01:15:17 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-10-17 14:26:27 +02:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* Class ClientController
|
|
|
|
* @package App\Http\Controllers
|
2019-04-04 11:28:53 +02:00
|
|
|
* @covers App\Http\Controllers\ClientController
|
2019-01-27 00:22:57 +01:00
|
|
|
*/
|
2019-03-28 22:34:58 +01:00
|
|
|
class ClientController extends BaseController
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2018-11-27 07:59:16 +01:00
|
|
|
use MakesHash;
|
2018-11-22 12:12:41 +01:00
|
|
|
|
2019-04-03 04:34:28 +02:00
|
|
|
protected $entity_type = Client::class;
|
2019-03-28 22:34:58 +01:00
|
|
|
|
2019-04-03 04:34:28 +02:00
|
|
|
protected $entity_transformer = ClientTransformer::class;
|
2019-03-28 22:34:58 +01:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* @var ClientRepository
|
|
|
|
*/
|
2019-04-23 08:19:45 +02:00
|
|
|
protected $client_repo;
|
2018-11-22 12:12:41 +01:00
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
* ClientController constructor.
|
|
|
|
* @param ClientRepository $clientRepo
|
|
|
|
*/
|
2019-04-23 08:19:45 +02:00
|
|
|
public function __construct(ClientRepository $client_repo)
|
2018-11-22 12:12:41 +01:00
|
|
|
{
|
2019-03-28 22:34:58 +01:00
|
|
|
parent::__construct();
|
2019-02-04 13:06:19 +01:00
|
|
|
|
2019-04-23 08:19:45 +02:00
|
|
|
$this->client_repo = $client_repo;
|
2019-02-04 13:06:19 +01:00
|
|
|
|
2018-11-22 12:12:41 +01:00
|
|
|
}
|
|
|
|
|
2019-01-27 00:22:57 +01:00
|
|
|
/**
|
|
|
|
*/
|
2019-03-28 11:07:45 +01:00
|
|
|
public function index(ClientFilters $filters)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-03-30 10:30:41 +01:00
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
$clients = Client::filter($filters);
|
2019-03-28 11:07:45 +01:00
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
return $this->listResponse($clients);
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-04 13:06:19 +01:00
|
|
|
* Display the specified resource.
|
2018-10-17 14:26:27 +02:00
|
|
|
*
|
2019-02-04 13:06:19 +01:00
|
|
|
* @param int $id
|
2018-10-17 14:26:27 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
public function show(ShowClientRequest $request, Client $client)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2018-12-02 11:42:06 +01:00
|
|
|
|
2019-04-03 03:17:21 +02:00
|
|
|
return $this->itemResponse($client);
|
2018-12-02 11:42:06 +01:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-04 13:06:19 +01:00
|
|
|
* Show the form for editing the specified resource.
|
2018-10-17 14:26:27 +02:00
|
|
|
*
|
2019-02-04 13:06:19 +01:00
|
|
|
* @param int $id
|
2018-10-17 14:26:27 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
public function edit(EditClientRequest $request, Client $client)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2018-12-02 11:42:06 +01:00
|
|
|
|
2019-04-03 03:17:21 +02:00
|
|
|
return $this->itemResponse($client);
|
2018-12-02 11:42:06 +01:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-04 13:06:19 +01:00
|
|
|
* Update the specified resource in storage.
|
2018-10-17 14:26:27 +02:00
|
|
|
*
|
2019-02-04 13:06:19 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param App\Models\Client $client
|
2018-10-17 14:26:27 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
public function update(UpdateClientRequest $request, Client $client)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-05-10 08:08:33 +02:00
|
|
|
|
|
|
|
$client = $this->client_repo->save($request->all(), $client);
|
2019-01-25 11:47:23 +01:00
|
|
|
|
2019-04-03 04:34:28 +02:00
|
|
|
return $this->itemResponse($client);
|
2019-01-25 11:47:23 +01:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-04 13:06:19 +01:00
|
|
|
* Show the form for creating a new resource.
|
2018-10-17 14:26:27 +02:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
public function create(CreateClientRequest $request)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-05-10 08:08:33 +02:00
|
|
|
|
2019-03-28 10:05:13 +01:00
|
|
|
$client = ClientFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
2019-02-04 13:06:19 +01:00
|
|
|
|
2019-04-03 04:34:28 +02:00
|
|
|
return $this->itemResponse($client);
|
2018-11-07 06:22:36 +01:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-04 13:06:19 +01:00
|
|
|
* Store a newly created resource in storage.
|
2018-10-17 14:26:27 +02:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
public function store(StoreClientRequest $request)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-06-12 01:15:17 +02:00
|
|
|
|
2019-05-10 08:08:33 +02:00
|
|
|
$client = $this->client_repo->save($request->all(), ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
2019-02-04 13:06:19 +01:00
|
|
|
|
|
|
|
$client->load('contacts', 'primary_contact');
|
|
|
|
|
2019-04-03 04:34:28 +02:00
|
|
|
return $this->itemResponse($client);
|
2018-11-10 14:24:36 +01:00
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-04-16 05:28:05 +02:00
|
|
|
public function destroy(DestroyClientRequest $request, Client $client)
|
2018-10-17 14:26:27 +02:00
|
|
|
{
|
2019-04-16 07:28:30 +02:00
|
|
|
//may not need these destroy routes as we are using actions to 'archive/delete'
|
2019-03-26 05:46:08 +01:00
|
|
|
$client->delete();
|
|
|
|
|
|
|
|
return response()->json([], 200);
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|
2018-10-29 04:16:17 +01:00
|
|
|
|
2019-01-19 11:35:21 +01:00
|
|
|
/**
|
|
|
|
* Perform bulk actions on the list view
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
2019-01-16 10:28:06 +01:00
|
|
|
public function bulk()
|
2019-01-13 11:42:03 +01:00
|
|
|
{
|
2019-01-21 15:06:49 +01:00
|
|
|
|
2019-01-19 11:35:21 +01:00
|
|
|
$action = request()->input('action');
|
2019-02-04 13:06:19 +01:00
|
|
|
|
2019-01-19 11:35:21 +01:00
|
|
|
$ids = request()->input('ids');
|
|
|
|
|
2019-01-20 06:00:50 +01:00
|
|
|
$clients = Client::withTrashed()->find($ids);
|
2019-01-19 11:35:21 +01:00
|
|
|
|
|
|
|
$clients->each(function ($client, $key) use($action){
|
2019-01-21 15:06:49 +01:00
|
|
|
|
|
|
|
if(auth()->user()->can('edit', $client))
|
2019-04-23 08:19:45 +02:00
|
|
|
$this->client_repo->{$action}($invoice);
|
2019-01-21 15:06:49 +01:00
|
|
|
|
2019-01-19 11:35:21 +01:00
|
|
|
});
|
2019-01-21 15:06:49 +01:00
|
|
|
|
2019-04-23 08:19:45 +02:00
|
|
|
return $this->listResponse(Client::withTrashed()->whereIn('id', $ids));
|
2019-01-21 15:06:49 +01:00
|
|
|
|
2019-01-13 11:42:03 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 13:06:19 +01:00
|
|
|
/**
|
|
|
|
* Returns a client statement
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
|
|
|
*/
|
|
|
|
public function statement()
|
|
|
|
{
|
|
|
|
//todo
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:06:49 +01:00
|
|
|
|
|
|
|
|
2018-10-17 14:26:27 +02:00
|
|
|
}
|