2015-10-28 20:22:07 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
|
|
|
use URL;
|
|
|
|
use Auth;
|
2015-10-28 20:22:07 +01:00
|
|
|
use App\Services\BaseService;
|
2016-03-16 00:08:00 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\Expense;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\Task;
|
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 extends BaseService
|
|
|
|
{
|
|
|
|
protected $clientRepo;
|
2015-11-05 23:37:04 +01:00
|
|
|
protected $datatableService;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->clientRepo;
|
|
|
|
}
|
|
|
|
|
2016-04-28 14:16:33 +02:00
|
|
|
public function save($data, $client = null)
|
2015-10-28 20:22:07 +01:00
|
|
|
{
|
2016-04-19 04:35:18 +02: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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|