2016-01-06 20:52:09 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
|
|
|
use Utils;
|
|
|
|
use URL;
|
|
|
|
use App\Services\BaseService;
|
|
|
|
use App\Ninja\Repositories\ExpenseRepository;
|
|
|
|
|
2016-01-07 12:04:01 +01:00
|
|
|
|
2016-01-06 20:52:09 +01:00
|
|
|
class ExpenseService extends BaseService
|
|
|
|
{
|
2016-01-07 16:14:11 +01:00
|
|
|
// Expenses
|
2016-01-06 20:52:09 +01:00
|
|
|
protected $expenseRepo;
|
|
|
|
protected $datatableService;
|
|
|
|
|
|
|
|
public function __construct(ExpenseRepository $expenseRepo, DatatableService $datatableService)
|
|
|
|
{
|
|
|
|
$this->expenseRepo = $expenseRepo;
|
|
|
|
$this->datatableService = $datatableService;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->expenseRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($data)
|
|
|
|
{
|
|
|
|
return $this->expenseRepo->save($data);
|
|
|
|
}
|
|
|
|
|
2016-01-07 12:04:01 +01:00
|
|
|
public function getDatatable($search)
|
2016-01-06 20:52:09 +01:00
|
|
|
{
|
2016-01-07 12:04:01 +01:00
|
|
|
$query = $this->expenseRepo->find($search);
|
2016-01-06 20:52:09 +01:00
|
|
|
|
2016-01-07 12:04:01 +01:00
|
|
|
return $this->createDatatable(ENTITY_EXPENSE, $query);
|
2016-01-06 20:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDatatableColumns($entityType, $hideClient)
|
|
|
|
{
|
|
|
|
return [
|
2016-01-07 12:04:01 +01:00
|
|
|
/*[
|
2016-01-06 20:52:09 +01:00
|
|
|
'vendor_name',
|
|
|
|
function ($model) {
|
|
|
|
return $model->vendor_public_id ? link_to("vendors/{$model->vendor_public_id}", Utils::getVendorDisplayName($model)) : '';
|
|
|
|
},
|
|
|
|
! $hideClient
|
2016-01-07 12:04:01 +01:00
|
|
|
],*/
|
2016-01-06 20:52:09 +01:00
|
|
|
[
|
|
|
|
'amount',
|
|
|
|
function ($model) {
|
2016-01-07 12:04:01 +01:00
|
|
|
return Utils::formatMoney($model->amount, false, false) . '<span '.Utils::getEntityRowClass($model).'/>';
|
2016-01-06 20:52:09 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'balance',
|
|
|
|
function ($model) {
|
2016-01-07 12:04:01 +01:00
|
|
|
return Utils::formatMoney($model->balance, false, false);
|
2016-01-06 20:52:09 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'expense_date',
|
|
|
|
function ($model) {
|
|
|
|
return Utils::fromSqlDate($model->expense_date);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2016-01-07 12:04:01 +01:00
|
|
|
'private_public',
|
2016-01-06 20:52:09 +01:00
|
|
|
function ($model) {
|
2016-01-07 12:04:01 +01:00
|
|
|
return $model->public_notes;
|
2016-01-06 20:52:09 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2016-01-07 12:04:01 +01:00
|
|
|
/*
|
2016-01-06 20:52:09 +01:00
|
|
|
protected function getDatatableActions($entityType)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
trans('texts.apply_expense'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("espense/create/{$model->vendor_public_id}") . '?paymentTypeId=1';
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2016-01-07 12:04:01 +01:00
|
|
|
*/
|
2016-01-06 20:52:09 +01:00
|
|
|
}
|