1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Services/VendorService.php

80 lines
1.7 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Services;
2016-01-06 15:23:58 +01:00
use App\Models\Vendor;
2016-05-23 20:07:06 +02:00
use App\Ninja\Datatables\VendorDatatable;
2017-01-30 20:40:43 +01:00
use App\Ninja\Repositories\NinjaRepository;
use App\Ninja\Repositories\VendorRepository;
use Auth;
use Utils;
2016-01-19 14:01:19 +01:00
/**
2017-01-30 20:40:43 +01:00
* Class VendorService.
*/
2016-01-06 15:23:58 +01:00
class VendorService extends BaseService
{
/**
* @var VendorRepository
*/
2016-01-06 15:23:58 +01:00
protected $vendorRepo;
/**
* @var DatatableService
*/
2016-01-06 15:23:58 +01:00
protected $datatableService;
/**
* VendorService constructor.
*
* @param VendorRepository $vendorRepo
* @param DatatableService $datatableService
2017-01-30 20:40:43 +01:00
* @param NinjaRepository $ninjaRepo
*/
public function __construct(
VendorRepository $vendorRepo,
DatatableService $datatableService,
NinjaRepository $ninjaRepo
2017-01-30 17:05:31 +01:00
) {
2017-01-30 20:40:43 +01:00
$this->vendorRepo = $vendorRepo;
$this->ninjaRepo = $ninjaRepo;
2016-01-06 15:23:58 +01:00
$this->datatableService = $datatableService;
}
/**
* @return VendorRepository
*/
2016-01-06 15:23:58 +01:00
protected function getRepo()
{
return $this->vendorRepo;
}
/**
2017-01-30 20:40:43 +01:00
* @param array $data
* @param Vendor|null $vendor
2017-01-30 20:40:43 +01:00
*
* @return mixed|null
*/
public function save(array $data, Vendor $vendor = null)
2016-01-06 15:23:58 +01:00
{
return $this->vendorRepo->save($data, $vendor);
2016-01-06 15:23:58 +01:00
}
/**
* @param $search
2017-01-30 20:40:43 +01:00
*
* @return \Illuminate\Http\JsonResponse
*/
2016-01-06 15:23:58 +01:00
public function getDatatable($search)
{
2016-05-23 20:07:06 +02:00
$datatable = new VendorDatatable();
2016-01-06 15:23:58 +01:00
$query = $this->vendorRepo->find($search);
2016-05-23 18:52:20 +02:00
2017-01-30 20:40:43 +01:00
if (! Utils::hasPermission('view_all')) {
$query->where('vendors.user_id', '=', Auth::user()->id);
}
2016-01-06 15:23:58 +01:00
2016-05-23 20:07:06 +02:00
return $this->datatableService->createDatatable($datatable, $query);
2016-01-06 15:23:58 +01:00
}
}