mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
b635f3b32e
* Wired up Bulk Archive / Delete / Restore button with reactivity on checkbox actions * Working on POSTing bulk actions * Working on Filtering by status * Add Action Entity * Implement Vuex for state management * Implement Vuex storage & list view bulk actions * Clean up console logs
181 lines
4.4 KiB
PHP
181 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Datatables\ClientDatatable;
|
|
use App\Http\Requests\Client\EditClientRequest;
|
|
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\Repositories\ClientRepository;
|
|
use App\Utils\Traits\MakesHash;
|
|
use App\Utils\Traits\MakesMenu;
|
|
use App\Utils\Traits\UserSessionAttributes;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
use Yajra\DataTables\Html\Builder;
|
|
|
|
class ClientController extends Controller
|
|
{
|
|
use UserSessionAttributes;
|
|
use MakesHash;
|
|
use MakesMenu;
|
|
|
|
protected $clientRepo;
|
|
|
|
protected $clientDatatable;
|
|
|
|
public function __construct(ClientRepository $clientRepo, ClientDatatable $clientDatatable)
|
|
{
|
|
$this->clientRepo = $clientRepo;
|
|
$this->clientDatatable = $clientDatatable;
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
if(request('page'))
|
|
return $this->clientDatatable->query(request(), $this->getCurrentCompanyId());
|
|
|
|
$data = [
|
|
'datatable' => $this->clientDatatable->buildOptions()
|
|
];
|
|
|
|
return view('client.vue_list', $data);
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$client = new Client;
|
|
$client->name = '';
|
|
$client->company_id = $this->getCurrentCompanyId();
|
|
$client_contact = new ClientContact;
|
|
$client_contact->first_name = "";
|
|
$client_contact->id = 0;
|
|
|
|
$client->contacts->add($client_contact);
|
|
|
|
$data = [
|
|
'client' => $client,
|
|
'hashed_id' => ''
|
|
];
|
|
|
|
return view('client.create', $data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreClientRequest $request)
|
|
{
|
|
$client = StoreClient::dispatchNow($request, new Client);
|
|
$client->load('contacts', 'primary_contact');
|
|
|
|
$client->hashed_id = $this->encodePrimarykey($client->id);
|
|
|
|
/*
|
|
$data = [
|
|
'client' => $client,
|
|
'hashed_id' => $this->encodePrimarykey($client->id)
|
|
];
|
|
*/
|
|
Log::error(print_r($client,1));
|
|
return response()->json($client, 200);
|
|
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$client = Client::find(2);
|
|
$client->load('contacts', 'primary_contact');
|
|
|
|
return response()->json($client, 200);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(EditClientRequest $request, Client $client)
|
|
{
|
|
|
|
$data = [
|
|
'client' => $client,
|
|
'settings' => [],
|
|
'pills' => $this->makeEntityTabMenu(Client::class),
|
|
'hashed_id' => $this->encodePrimarykey($client->id)
|
|
];
|
|
|
|
return view('client.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$client = UpdateClient::dispatchNow($request, $client);
|
|
$client->load('contacts', 'primary_contact');
|
|
|
|
return response()->json($client, 200);
|
|
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Perform bulk actions on the list view
|
|
*
|
|
* @return Collection
|
|
*/
|
|
public function bulk()
|
|
{
|
|
$action = request()->input('action');
|
|
$ids = request()->input('ids');
|
|
|
|
$clients = Client::find($ids);
|
|
|
|
$clients->each(function ($client, $key) use($action){
|
|
ActionEntity::dispatchNow($client, $action);
|
|
});
|
|
//todo need to return the updated dataset
|
|
return response()->json('success', 200);
|
|
}
|
|
|
|
}
|