1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Services/RecurringInvoiceService.php

82 lines
2.4 KiB
PHP
Raw Normal View History

2015-11-05 23:37:04 +01:00
<?php namespace App\Services;
use URL;
2016-03-16 00:08:00 +01:00
use Auth;
2015-11-05 23:37:04 +01:00
use Utils;
2016-03-16 00:08:00 +01:00
use App\Models\Invoice;
2015-11-05 23:37:04 +01:00
use App\Ninja\Repositories\InvoiceRepository;
class RecurringInvoiceService extends BaseService
{
protected $invoiceRepo;
protected $datatableService;
public function __construct(InvoiceRepository $invoiceRepo, DatatableService $datatableService)
{
$this->invoiceRepo = $invoiceRepo;
$this->datatableService = $datatableService;
}
public function getDatatable($accountId, $clientPublicId = null, $entityType, $search)
{
$query = $this->invoiceRepo->getRecurringInvoices($accountId, $clientPublicId, $search);
2016-03-16 00:08:00 +01:00
if(!Utils::hasPermission('view_all')){
$query->where('invoices.user_id', '=', Auth::user()->id);
}
2015-11-05 23:37:04 +01:00
return $this->createDatatable(ENTITY_RECURRING_INVOICE, $query, !$clientPublicId);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'frequency',
function ($model) {
2016-03-02 14:36:42 +01:00
return link_to("invoices/{$model->public_id}", $model->frequency)->toHtml();
2015-11-05 23:37:04 +01:00
}
],
[
'client_name',
function ($model) {
2016-03-02 14:36:42 +01:00
return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml();
2015-11-05 23:37:04 +01:00
},
! $hideClient
],
[
'start_date',
function ($model) {
return Utils::fromSqlDate($model->start_date);
}
],
[
'end_date',
function ($model) {
return Utils::fromSqlDate($model->end_date);
}
],
[
'amount',
function ($model) {
return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id);
2015-11-05 23:37:04 +01:00
}
]
];
}
protected function getDatatableActions($entityType)
{
return [
[
trans('texts.edit_invoice'),
function ($model) {
return URL::to("invoices/{$model->public_id}/edit");
2016-03-16 00:08:00 +01:00
},
function ($model) {
return Invoice::canEditItem($model);
2015-11-05 23:37:04 +01:00
}
]
];
}
}