2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
2015-11-05 23:37:04 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Ninja\Datatables\RecurringInvoiceDatatable;
|
|
|
|
use App\Ninja\Repositories\InvoiceRepository;
|
2016-03-16 00:08:00 +01:00
|
|
|
use Auth;
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
|
|
|
|
|
|
|
class RecurringInvoiceService extends BaseService
|
|
|
|
{
|
|
|
|
protected $invoiceRepo;
|
|
|
|
protected $datatableService;
|
|
|
|
|
|
|
|
public function __construct(InvoiceRepository $invoiceRepo, DatatableService $datatableService)
|
|
|
|
{
|
|
|
|
$this->invoiceRepo = $invoiceRepo;
|
|
|
|
$this->datatableService = $datatableService;
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
public function getDatatable($accountId, $clientPublicId, $entityType, $search)
|
2015-11-05 23:37:04 +01:00
|
|
|
{
|
2016-11-24 10:22:37 +01:00
|
|
|
$datatable = new RecurringInvoiceDatatable(true, $clientPublicId);
|
2015-11-05 23:37:04 +01:00
|
|
|
$query = $this->invoiceRepo->getRecurringInvoices($accountId, $clientPublicId, $search);
|
|
|
|
|
2018-06-07 12:08:34 +02:00
|
|
|
if (! Utils::hasPermission('view_recurring_invoice')) {
|
2016-03-16 00:08:00 +01:00
|
|
|
$query->where('invoices.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
|
|
|
}
|