1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/ProductService.php

84 lines
2.0 KiB
PHP
Raw Normal View History

2015-11-05 23:37:04 +01:00
<?php namespace App\Services;
use Utils;
use Str;
use DB;
use Auth;
use URL;
use App\Services\BaseService;
use App\Ninja\Repositories\ProductRepository;
class ProductService extends BaseService
{
protected $datatableService;
protected $productRepo;
public function __construct(DatatableService $datatableService, ProductRepository $productRepo)
{
$this->datatableService = $datatableService;
$this->productRepo = $productRepo;
}
protected function getRepo()
{
return $this->productRepo;
}
/*
public function save()
{
return null;
}
*/
public function getDatatable($accountId)
{
$query = $this->productRepo->find($accountId);
return $this->createDatatable(ENTITY_PRODUCT, $query, false);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'product_key',
function ($model) {
return link_to('products/'.$model->public_id.'/edit', $model->product_key);
}
],
[
'notes',
function ($model) {
return nl2br(Str::limit($model->notes, 100));
}
],
[
'cost',
function ($model) {
return Utils::formatMoney($model->cost);
}
],
[
'tax_rate',
function ($model) {
return $model->tax_rate ? ($model->tax_name . ' ' . $model->tax_rate . '%') : '';
},
Auth::user()->account->invoice_item_taxes
]
];
}
protected function getDatatableActions($entityType)
{
return [
[
uctrans('texts.edit_product'),
function ($model) {
return URL::to("products/{$model->public_id}/edit");
}
]
];
}
}