1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/VendorService.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2016-01-06 15:23:58 +01:00
<?php namespace App\Services;
use App\Models\Vendor;
2016-01-06 15:23:58 +01:00
use Utils;
use Auth;
use App\Ninja\Repositories\VendorRepository;
use App\Ninja\Repositories\NinjaRepository;
2016-05-23 20:07:06 +02:00
use App\Ninja\Datatables\VendorDatatable;
2016-01-19 14:01:19 +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
* @param NinjaRepository $ninjaRepo
*/
public function __construct(
VendorRepository $vendorRepo,
DatatableService $datatableService,
NinjaRepository $ninjaRepo
)
2016-01-06 15:23:58 +01:00
{
2016-01-19 14:01:19 +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;
}
/**
* @param array $data
* @param Vendor|null $vendor
* @return mixed|null
*/
public function save(array $data, Vendor $vendor = null)
2016-01-06 15:23:58 +01:00
{
if (Auth::user()->account->isNinjaAccount() && isset($data['plan'])) {
$this->ninjaRepo->updatePlanDetails($data['public_id'], $data);
2016-01-06 15:23:58 +01:00
}
return $this->vendorRepo->save($data, $vendor);
2016-01-06 15:23:58 +01:00
}
/**
* @param $search
* @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
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
}
}