1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Services/ExpenseService.php

116 lines
3.2 KiB
PHP
Raw Normal View History

2016-01-06 20:52:09 +01:00
<?php namespace App\Services;
2016-01-08 19:01:00 +01:00
use DB;
2016-01-06 20:52:09 +01:00
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-08 19:01:00 +01:00
[
2016-01-09 06:24:43 +01:00
'vendor_name',
2016-01-08 19:01:00 +01:00
function ($model)
{
2016-01-09 06:24:43 +01:00
if($model->vendor_public_id) {
return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name);
2016-01-08 19:01:00 +01:00
} else {
2016-01-09 06:24:43 +01:00
return 'No vendor' ;
2016-01-08 19:01:00 +01:00
}
2016-01-09 06:24:43 +01:00
}
2016-01-08 19:01:00 +01:00
],
2016-01-06 20:52:09 +01:00
[
'amount',
function ($model) {
2016-01-08 19:01:00 +01:00
return Utils::formatMoney($model->amount, false, false);
2016-01-06 20:52:09 +01:00
}
],
[
2016-01-08 19:01:00 +01:00
'expense_date',
2016-01-06 20:52:09 +01:00
function ($model) {
2016-01-08 19:01:00 +01:00
return Utils::fromSqlDate($model->expense_date);
2016-01-06 20:52:09 +01:00
}
],
[
2016-01-08 19:01:00 +01:00
'public_notes',
2016-01-06 20:52:09 +01:00
function ($model) {
2016-01-08 19:01:00 +01:00
return $model->public_notes != null ? $model->public_notes : '';
2016-01-06 20:52:09 +01:00
}
],
[
2016-01-08 19:01:00 +01:00
'is_invoiced',
2016-01-06 20:52:09 +01:00
function ($model) {
2016-01-09 06:24:43 +01:00
return $model->is_invoiced ? trans('texts.yes') : trans('texts.no');
2016-01-06 20:52:09 +01:00
}
2016-01-08 19:01:00 +01:00
],
[
'should_be_invoiced',
function ($model) {
return $model->should_be_invoiced ? trans('texts.yes') : trans('texts.no');
}
],
2016-01-09 06:24:43 +01:00
/*[
2016-01-08 19:01:00 +01:00
'public_id',
function($model) {
2016-01-09 06:24:43 +01:00
return link_to("expenses/{$model->public_id}", trans('texts.view', ['expense' => $model->public_id]));
2016-01-08 19:01:00 +01:00
}
2016-01-09 06:24:43 +01:00
]*/
2016-01-06 20:52:09 +01:00
];
}
2016-01-09 06:24:43 +01:00
2016-01-06 20:52:09 +01:00
protected function getDatatableActions($entityType)
{
2016-01-09 06:24:43 +01:00
return [
2016-01-06 20:52:09 +01:00
[
2016-01-09 06:24:43 +01:00
trans('texts.invoice_expense'),
2016-01-06 20:52:09 +01:00
function ($model) {
2016-01-09 06:24:43 +01:00
return URL::to("expense/invoice/{$model->public_id}") . '?client=1';
2016-01-06 20:52:09 +01:00
}
2016-01-09 06:24:43 +01:00
],
[
trans('texts.view'),
function ($model) {
return URL::to("expenses/{$model->public_id}") ;
}
],
2016-01-09 09:08:24 +01:00
[
trans('texts.edit'),
function ($model) {
return URL::to("expenses/{$model->public_id}/edit") ;
}
],
2016-01-09 06:24:43 +01:00
2016-01-06 20:52:09 +01:00
];
}
}