1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Services/ClientService.php

127 lines
3.5 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;
use Auth;
2015-10-28 20:22:07 +01:00
use App\Services\BaseService;
use App\Ninja\Repositories\ClientRepository;
class ClientService extends BaseService
{
protected $clientRepo;
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(ClientRepository $clientRepo, DatatableService $datatableService)
2015-10-28 20:22:07 +01:00
{
$this->clientRepo = $clientRepo;
2015-11-05 23:37:04 +01:00
$this->datatableService = $datatableService;
2015-10-28 20:22:07 +01:00
}
protected function getRepo()
{
return $this->clientRepo;
}
public function save($data)
{
return $this->clientRepo->save($data);
}
2015-11-05 23:37:04 +01:00
public function getDatatable($search)
{
$query = $this->clientRepo->find($search);
return $this->createDatatable(ENTITY_CLIENT, $query);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'name',
function ($model) {
return link_to("clients/{$model->public_id}", $model->name);
}
],
[
'first_name',
function ($model) {
return link_to("clients/{$model->public_id}", $model->first_name.' '.$model->last_name);
}
],
[
'email',
function ($model) {
return link_to("clients/{$model->public_id}", $model->email);
}
],
[
'clients.created_at',
function ($model) {
return Utils::timestampToDateString(strtotime($model->created_at));
}
],
[
'last_login',
function ($model) {
return Utils::timestampToDateString(strtotime($model->last_login));
}
],
[
'balance',
function ($model) {
return Utils::formatMoney($model->balance, $model->currency_id);
}
]
];
}
protected function getDatatableActions($entityType)
{
return [
[
trans('texts.edit_client'),
function ($model) {
return URL::to("clients/{$model->public_id}/edit");
}
],
[],
[
trans('texts.new_task'),
function ($model) {
return URL::to("tasks/create/{$model->public_id}");
}
],
[
trans('texts.new_invoice'),
function ($model) {
return URL::to("invoices/create/{$model->public_id}");
}
],
[
trans('texts.new_quote'),
function ($model) {
return URL::to("quotes/create/{$model->public_id}");
},
function ($model) {
return Auth::user()->isPro();
}
],
[],
[
trans('texts.enter_payment'),
function ($model) {
return URL::to("payments/create/{$model->public_id}");
}
],
[
trans('texts.enter_credit'),
function ($model) {
return URL::to("credits/create/{$model->public_id}");
}
]
];
}
}