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

77 lines
1.7 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
2015-10-28 20:22:07 +01:00
2017-01-30 20:40:43 +01:00
namespace App\Services;
use App\Ninja\Datatables\ClientDatatable;
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;
2017-01-30 20:40:43 +01:00
use Auth;
2015-10-28 20:22:07 +01:00
/**
2017-01-30 20:40:43 +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.
2017-01-30 20:40:43 +01:00
*
* @param ClientRepository $clientRepo
* @param DatatableService $datatableService
2017-01-30 20:40:43 +01:00
* @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
2017-01-30 20:40:43 +01:00
*
* @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
2017-01-30 20:40:43 +01:00
*
* @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
}
}