1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/CreditService.php

70 lines
1.6 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 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
/**
* Class CreditService
*/
2015-10-28 20:22:07 +01:00
class CreditService extends BaseService
{
/**
* @var CreditRepository
*/
2015-10-28 20:22:07 +01:00
protected $creditRepo;
/**
* @var DatatableService
*/
2015-11-05 23:37:04 +01:00
protected $datatableService;
2015-10-28 20:22:07 +01: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
}
/**
* @return CreditRepository
*/
2015-10-28 20:22:07 +01:00
protected function getRepo()
{
return $this->creditRepo;
}
/**
* @param $data
* @return mixed|null
*/
2015-10-28 20:22:07 +01:00
public function save($data)
{
return $this->creditRepo->save($data);
}
2015-11-05 23:37:04 +01: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
$datatable = new CreditDatatable( ! $clientPublicId, $clientPublicId);
2015-11-05 23:37:04 +01:00
$query = $this->creditRepo->find($clientPublicId, $search);
2016-05-23 18:52:20 +02:00
if(!Utils::hasPermission('view_all')){
2016-03-17 15:11:14 +01:00
$query->where('credits.user_id', '=', Auth::user()->id);
}
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
}