2015-10-28 20:22:07 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
2016-03-17 15:11:14 +01:00
|
|
|
use Auth;
|
2015-10-28 20:22:07 +01:00
|
|
|
use App\Ninja\Repositories\CreditRepository;
|
2016-05-23 18:52:20 +02:00
|
|
|
use App\Ninja\Datatables\CreditDatatable;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class CreditService
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
class CreditService extends BaseService
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var CreditRepository
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
protected $creditRepo;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DatatableService
|
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
protected $datatableService;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* CreditService constructor.
|
|
|
|
*
|
|
|
|
* @param CreditRepository $creditRepo
|
|
|
|
* @param DatatableService $datatableService
|
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
public function __construct(CreditRepository $creditRepo, DatatableService $datatableService)
|
2015-10-28 20:22:07 +01:00
|
|
|
{
|
|
|
|
$this->creditRepo = $creditRepo;
|
2015-11-05 23:37:04 +01:00
|
|
|
$this->datatableService = $datatableService;
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return CreditRepository
|
|
|
|
*/
|
2015-10-28 20:22:07 +01:00
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->creditRepo;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @return mixed|null
|
|
|
|
*/
|
2016-11-30 19:21:50 +01:00
|
|
|
public function save($data, $credit = null)
|
2015-10-28 20:22:07 +01:00
|
|
|
{
|
2016-11-30 19:21:50 +01:00
|
|
|
return $this->creditRepo->save($data, $credit);
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|
2015-11-05 23:37:04 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $clientPublicId
|
|
|
|
* @param $search
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
public function getDatatable($clientPublicId, $search)
|
|
|
|
{
|
2016-05-23 18:52:20 +02:00
|
|
|
// we don't support bulk edit and hide the client on the individual client page
|
2016-11-24 10:22:37 +01:00
|
|
|
$datatable = new CreditDatatable(true, $clientPublicId);
|
2015-11-05 23:37:04 +01:00
|
|
|
$query = $this->creditRepo->find($clientPublicId, $search);
|
2016-05-23 18:52:20 +02:00
|
|
|
|
2016-03-16 03:07:11 +01:00
|
|
|
if(!Utils::hasPermission('view_all')){
|
2016-03-17 15:11:14 +01:00
|
|
|
$query->where('credits.user_id', '=', Auth::user()->id);
|
2016-03-16 03:07:11 +01:00
|
|
|
}
|
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
|
|
|
}
|
2016-05-23 18:52:20 +02:00
|
|
|
}
|