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
|
|
|
[
|
|
|
|
'vendor_id',
|
|
|
|
function ($model)
|
|
|
|
{
|
|
|
|
if($model->vendor_id) {
|
|
|
|
|
|
|
|
$vendors = DB::table('vendors')->where('public_id', '=',$model->vendor_id)->select('id', 'public_id','name')->get();
|
|
|
|
// should only be one!
|
|
|
|
$vendor = $vendors[0];
|
|
|
|
|
|
|
|
if($vendor) {
|
|
|
|
return link_to("vendors/{$vendor->public_id}", $vendor->name);
|
|
|
|
}
|
|
|
|
return 'no vendor: ' . $model->vendor_id;
|
|
|
|
} else {
|
|
|
|
return 'No vendor:' ;
|
|
|
|
}
|
2016-01-06 20:52:09 +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-08 19:01:00 +01:00
|
|
|
return $model->is_invoiced ? trans('texts.expense_is_invoiced') : trans('texts.expense_is_not_invoiced');
|
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');
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'public_id',
|
|
|
|
function($model) {
|
|
|
|
return link_to("expenses/{$model->public_id}", trans('texts.view_expense', ['expense' => $model->public_id]));
|
|
|
|
}
|
|
|
|
]
|
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
|
|
|
}
|