1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/ClientService.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2015-10-28 20:22:07 +01:00
<?php namespace App\Services;
2015-11-05 23:37:04 +01:00
use Auth;
2015-10-28 20:22:07 +01:00
use App\Ninja\Repositories\ClientRepository;
2015-11-09 20:24:22 +01:00
use App\Ninja\Repositories\NinjaRepository;
2016-05-23 18:52:20 +02:00
use App\Ninja\Datatables\ClientDatatable;
2015-10-28 20:22:07 +01:00
/**
* Class ClientService
*/
2015-10-28 20:22:07 +01:00
class ClientService extends BaseService
{
/**
* @var ClientRepository
*/
2015-10-28 20:22:07 +01:00
protected $clientRepo;
/**
* @var DatatableService
*/
2015-11-05 23:37:04 +01:00
protected $datatableService;
2015-10-28 20:22:07 +01:00
/**
* ClientService constructor.
* @param ClientRepository $clientRepo
* @param DatatableService $datatableService
* @param NinjaRepository $ninjaRepo
*/
2015-11-09 20:24:22 +01:00
public function __construct(ClientRepository $clientRepo, DatatableService $datatableService, NinjaRepository $ninjaRepo)
2015-10-28 20:22:07 +01:00
{
$this->clientRepo = $clientRepo;
2015-11-09 20:24:22 +01:00
$this->ninjaRepo = $ninjaRepo;
2015-11-05 23:37:04 +01:00
$this->datatableService = $datatableService;
2015-10-28 20:22:07 +01:00
}
/**
* @return ClientRepository
*/
2015-10-28 20:22:07 +01:00
protected function getRepo()
{
return $this->clientRepo;
}
/**
* @param $data
* @param null $client
* @return mixed|null
*/
2016-04-28 14:16:33 +02:00
public function save($data, $client = null)
2015-10-28 20:22:07 +01:00
{
if (Auth::user()->account->isNinjaAccount() && isset($data['plan'])) {
$this->ninjaRepo->updatePlanDetails($data['public_id'], $data);
2015-11-09 20:24:22 +01:00
}
2016-04-28 14:16:33 +02:00
return $this->clientRepo->save($data, $client);
2015-10-28 20:22:07 +01:00
}
2015-11-05 23:37:04 +01:00
/**
* @param $search
* @param $userId
* @return \Illuminate\Http\JsonResponse
*/
2016-05-23 18:52:20 +02:00
public function getDatatable($search, $userId)
2015-11-05 23:37:04 +01:00
{
2016-05-23 18:52:20 +02:00
$datatable = new ClientDatatable();
2015-11-05 23:37:04 +01:00
2016-05-23 18:52:20 +02:00
$query = $this->clientRepo->find($search, $userId);
2015-11-05 23:37:04 +01:00
2016-05-23 18:52:20 +02:00
return $this->datatableService->createDatatable($datatable, $query);
2015-11-05 23:37:04 +01:00
}
}