1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00
invoiceninja/app/Services/CreditService.php

75 lines
1.7 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Services;
2015-10-28 20:22:07 +01:00
2016-05-23 18:52:20 +02:00
use App\Ninja\Datatables\CreditDatatable;
2017-01-30 20:40:43 +01:00
use App\Ninja\Repositories\CreditRepository;
use Auth;
use Utils;
2015-10-28 20:22:07 +01:00
/**
2017-01-30 20:40:43 +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
2017-01-30 20:49:42 +01:00
* @param null|mixed $credit
2017-01-30 20:40:43 +01:00
*
* @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
/**
* @param $clientPublicId
* @param $search
2017-01-30 20:40:43 +01:00
*
* @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(true, $clientPublicId);
2015-11-05 23:37:04 +01:00
$query = $this->creditRepo->find($clientPublicId, $search);
2016-05-23 18:52:20 +02:00
2017-01-30 20:40:43 +01: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
}