2015-10-28 20:22:07 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
|
|
|
use URL;
|
2015-10-28 20:22:07 +01:00
|
|
|
use App\Services\BaseService;
|
|
|
|
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);
|
|
|
|
|
|
|
|
return $this->createDatatable(ENTITY_CREDIT, $query, !$clientPublicId);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDatatableColumns($entityType, $hideClient)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'client_name',
|
|
|
|
function ($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) {
|
2015-12-07 14:34:55 +01:00
|
|
|
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) {
|
2015-12-07 14:34:55 +01:00
|
|
|
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';
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|