2015-10-28 20:22:07 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
|
|
|
use URL;
|
2016-03-17 15:11:14 +01:00
|
|
|
use Auth;
|
2015-10-28 20:22:07 +01:00
|
|
|
use App\Services\BaseService;
|
2016-03-16 03:07:11 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\Payment;
|
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 extends BaseService
|
|
|
|
{
|
|
|
|
protected $creditRepo;
|
2015-11-05 23:37:04 +01:00
|
|
|
protected $datatableService;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->creditRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($data)
|
|
|
|
{
|
|
|
|
return $this->creditRepo->save($data);
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
}
|