1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Controllers/ClientController.php

205 lines
4.7 KiB
PHP
Raw Normal View History

<?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
*/
namespace App\Http\Controllers;
use App\DataMapper\ClientSettings;
use App\Factory\ClientFactory;
2019-03-28 11:07:45 +01:00
use App\Filters\ClientFilters;
use App\Http\Requests\Client\CreateClientRequest;
use App\Http\Requests\Client\DestroyClientRequest;
use App\Http\Requests\Client\EditClientRequest;
use App\Http\Requests\Client\ShowClientRequest;
use App\Http\Requests\Client\StoreClientRequest;
use App\Http\Requests\Client\UpdateClientRequest;
use App\Jobs\Client\StoreClient;
use App\Jobs\Client\UpdateClient;
use App\Jobs\Entity\ActionEntity;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Size;
2019-04-23 08:19:45 +02:00
use App\Repositories\BaseRepository;
use App\Repositories\ClientRepository;
use App\Transformers\ClientTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
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
{
use MakesHash;
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;
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)
{
2019-03-28 22:34:58 +01:00
parent::__construct();
2019-04-23 08:19:45 +02:00
$this->client_repo = $client_repo;
}
2019-01-27 00:22:57 +01:00
/**
*/
2019-03-28 11:07:45 +01:00
public function index(ClientFilters $filters)
{
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);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show(ShowClientRequest $request, Client $client)
{
2019-04-03 03:17:21 +02:00
return $this->itemResponse($client);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit(EditClientRequest $request, Client $client)
{
2019-04-03 03:17:21 +02:00
return $this->itemResponse($client);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param App\Models\Client $client
* @return \Illuminate\Http\Response
*/
public function update(UpdateClientRequest $request, Client $client)
{
2019-05-10 08:08:33 +02:00
$client = $this->client_repo->save($request->all(), $client);
2019-04-03 04:34:28 +02:00
return $this->itemResponse($client);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(CreateClientRequest $request)
{
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-04-03 04:34:28 +02:00
return $this->itemResponse($client);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(StoreClientRequest $request)
{
2019-05-10 08:08:33 +02:00
$client = $this->client_repo->save($request->all(), ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
$client->load('contacts', 'primary_contact');
2019-04-03 04:34:28 +02:00
return $this->itemResponse($client);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(DestroyClientRequest $request, Client $client)
{
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);
}
/**
* Perform bulk actions on the list view
*
* @return Collection
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$clients = Client::withTrashed()->find($ids);
$clients->each(function ($client, $key) use($action){
if(auth()->user()->can('edit', $client))
2019-04-23 08:19:45 +02:00
$this->client_repo->{$action}($invoice);
});
2019-04-23 08:19:45 +02:00
return $this->listResponse(Client::withTrashed()->whereIn('id', $ids));
}
/**
* Returns a client statement
*
* @return [type] [description]
*/
public function statement()
{
//todo
}
}