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

132 lines
3.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;
use Auth;
2015-10-28 20:22:07 +01:00
use App\Services\BaseService;
use App\Ninja\Repositories\ClientRepository;
2015-11-09 20:24:22 +01:00
use App\Ninja\Repositories\NinjaRepository;
2015-10-28 20:22:07 +01:00
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-09 20:24:22 +01:00
public function __construct(ClientRepository $clientRepo, DatatableService $datatableService, NinjaRepository $ninjaRepo)
2015-10-28 20:22:07 +01:00
{
$this->clientRepo = $clientRepo;
2015-11-09 20:24:22 +01:00
$this->ninjaRepo = $ninjaRepo;
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)
{
2015-11-09 20:24:22 +01:00
if (Auth::user()->account->isNinjaAccount() && isset($data['pro_plan_paid'])) {
$this->ninjaRepo->updateProPlanPaid($data['public_id'], $data['pro_plan_paid']);
}
2015-10-28 20:22:07 +01:00
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) {
2015-11-09 20:24:22 +01:00
return link_to("clients/{$model->public_id}", $model->name ?: '');
2015-11-05 23:37:04 +01:00
}
],
[
'first_name',
function ($model) {
return link_to("clients/{$model->public_id}", $model->first_name.' '.$model->last_name);
}
],
[
'email',
function ($model) {
2015-11-09 20:24:22 +01:00
return link_to("clients/{$model->public_id}", $model->email ?: '');
2015-11-05 23:37:04 +01:00
}
],
[
'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, $model->country_id);
2015-11-05 23:37:04 +01:00
}
]
];
}
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}");
}
]
];
}
}