2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Datatables;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
use Auth;
|
2017-01-30 20:40:43 +01:00
|
|
|
use URL;
|
|
|
|
use Utils;
|
2017-03-09 14:08:18 +01:00
|
|
|
use App\Models\Invoice;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
class RecurringInvoiceDatatable extends EntityDatatable
|
|
|
|
{
|
|
|
|
public $entityType = ENTITY_RECURRING_INVOICE;
|
|
|
|
|
|
|
|
public function columns()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'frequency',
|
|
|
|
function ($model) {
|
2017-06-28 16:39:32 +02:00
|
|
|
if ($model->frequency) {
|
|
|
|
$frequency = strtolower($model->frequency);
|
|
|
|
$frequency = preg_replace('/\s/', '_', $frequency);
|
|
|
|
$label = trans('texts.freq_' . $frequency);
|
|
|
|
} else {
|
|
|
|
$label = trans('texts.freq_inactive');
|
|
|
|
}
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2017-06-28 16:39:32 +02:00
|
|
|
return link_to("recurring_invoices/{$model->public_id}/edit", $label)->toHtml();
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'client_name',
|
|
|
|
function ($model) {
|
|
|
|
return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml();
|
|
|
|
},
|
2017-01-30 20:40:43 +01:00
|
|
|
! $this->hideClient,
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'start_date',
|
|
|
|
function ($model) {
|
2017-03-28 11:40:53 +02:00
|
|
|
return Utils::fromSqlDate($model->start_date_sql);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
2017-01-22 21:43:17 +01:00
|
|
|
[
|
|
|
|
'last_sent',
|
|
|
|
function ($model) {
|
2017-03-28 11:40:53 +02:00
|
|
|
return Utils::fromSqlDate($model->last_sent_date_sql);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2017-01-22 21:43:17 +01:00
|
|
|
],
|
2017-05-16 20:37:26 +02:00
|
|
|
/*
|
2016-05-23 18:52:20 +02:00
|
|
|
[
|
|
|
|
'end_date',
|
|
|
|
function ($model) {
|
2017-03-28 11:40:53 +02:00
|
|
|
return Utils::fromSqlDate($model->end_date_sql);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-05-23 18:52:20 +02:00
|
|
|
],
|
2017-05-16 20:37:26 +02:00
|
|
|
*/
|
2016-05-23 18:52:20 +02:00
|
|
|
[
|
|
|
|
'amount',
|
|
|
|
function ($model) {
|
|
|
|
return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
|
|
|
],
|
2017-05-16 20:37:26 +02:00
|
|
|
[
|
|
|
|
'private_notes',
|
|
|
|
function ($model) {
|
|
|
|
return $model->private_notes;
|
|
|
|
},
|
|
|
|
],
|
2017-03-09 14:08:18 +01:00
|
|
|
[
|
|
|
|
'status',
|
|
|
|
function ($model) {
|
|
|
|
return self::getStatusLabel($model);
|
|
|
|
},
|
|
|
|
],
|
2016-05-23 18:52:20 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-03-09 14:08:18 +01:00
|
|
|
private function getStatusLabel($model)
|
|
|
|
{
|
2017-03-28 11:40:53 +02:00
|
|
|
$class = Invoice::calcStatusClass($model->invoice_status_id, $model->balance, $model->due_date_sql, $model->is_recurring);
|
2017-03-09 14:08:18 +01:00
|
|
|
$label = Invoice::calcStatusLabel($model->invoice_status_name, $class, $this->entityType, $model->quote_invoice_id);
|
|
|
|
|
2017-03-28 11:40:53 +02:00
|
|
|
if ($model->invoice_status_id == INVOICE_STATUS_SENT && (! $model->last_sent_date_sql || $model->last_sent_date_sql == '0000-00-00')) {
|
2017-03-09 14:08:18 +01:00
|
|
|
$label = trans('texts.pending');
|
|
|
|
}
|
|
|
|
|
|
|
|
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
|
|
|
}
|
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
trans('texts.edit_invoice'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("invoices/{$model->public_id}/edit");
|
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-09-26 08:54:59 +02:00
|
|
|
],
|
|
|
|
[
|
2017-01-30 20:40:43 +01:00
|
|
|
trans('texts.clone_invoice'),
|
2016-09-26 08:54:59 +02:00
|
|
|
function ($model) {
|
|
|
|
return URL::to("invoices/{$model->public_id}/clone");
|
|
|
|
},
|
|
|
|
function ($model) {
|
|
|
|
return Auth::user()->can('create', ENTITY_INVOICE);
|
2017-01-30 20:40:43 +01:00
|
|
|
},
|
2016-09-26 08:54:59 +02:00
|
|
|
],
|
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|