1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/CreditService.php

99 lines
2.8 KiB
PHP
Raw Normal View History

2015-10-28 20:22:07 +01:00
<?php namespace App\Services;
2015-11-05 23:37:04 +01:00
use Utils;
use URL;
2016-03-17 15:11:14 +01:00
use Auth;
2015-10-28 20:22:07 +01:00
use App\Services\BaseService;
use App\Models\Client;
use App\Models\Payment;
2015-10-28 20:22:07 +01:00
use App\Ninja\Repositories\CreditRepository;
class CreditService extends BaseService
{
protected $creditRepo;
2015-11-05 23:37:04 +01:00
protected $datatableService;
2015-10-28 20:22:07 +01:00
2015-11-05 23:37:04 +01:00
public function __construct(CreditRepository $creditRepo, DatatableService $datatableService)
2015-10-28 20:22:07 +01:00
{
$this->creditRepo = $creditRepo;
2015-11-05 23:37:04 +01:00
$this->datatableService = $datatableService;
2015-10-28 20:22:07 +01:00
}
protected function getRepo()
{
return $this->creditRepo;
}
public function save($data)
{
return $this->creditRepo->save($data);
}
2015-11-05 23:37:04 +01:00
public function getDatatable($clientPublicId, $search)
{
$query = $this->creditRepo->find($clientPublicId, $search);
if(!Utils::hasPermission('view_all')){
2016-03-17 15:11:14 +01:00
$query->where('credits.user_id', '=', Auth::user()->id);
}
2015-11-05 23:37:04 +01:00
return $this->createDatatable(ENTITY_CREDIT, $query, !$clientPublicId);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'client_name',
function ($model) {
if(!Client::canViewItemByOwner($model->client_user_id)){
return Utils::getClientDisplayName($model);
}
2016-03-02 14:36:42 +01:00
return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml() : '';
2015-11-05 23:37:04 +01:00
},
! $hideClient
],
[
'amount',
function ($model) {
return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id) . '<span '.Utils::getEntityRowClass($model).'/>';
2015-11-05 23:37:04 +01:00
}
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, $model->currency_id, $model->country_id);
2015-11-05 23:37:04 +01:00
}
],
[
'credit_date',
function ($model) {
return Utils::fromSqlDate($model->credit_date);
}
],
[
'private_notes',
function ($model) {
return $model->private_notes;
}
]
];
}
protected function getDatatableActions($entityType)
{
return [
[
trans('texts.apply_credit'),
function ($model) {
return URL::to("payments/create/{$model->client_public_id}") . '?paymentTypeId=1';
},
function ($model) {
return Payment::canCreate();
2015-11-05 23:37:04 +01:00
}
]
];
}
2015-10-28 20:22:07 +01:00
}