mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 14:30:57 -04:00
Fixes for expense categories
This commit is contained in:
parent
28f140ee37
commit
5b2a43bd9a
31
app/Factory/ExpenseCategoryFactory.php
Normal file
31
app/Factory/ExpenseCategoryFactory.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\Models\ExpenseCategory;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class ExpenseCategoryFactory
|
||||||
|
{
|
||||||
|
public static function create(int $company_id, int $user_id) :ExpenseCategory
|
||||||
|
{
|
||||||
|
$expense = new ExpenseCategory();
|
||||||
|
$expense->user_id = $user_id;
|
||||||
|
$expense->company_id = $company_id;
|
||||||
|
$expense->name = '';
|
||||||
|
$expense->is_deleted = false;;
|
||||||
|
|
||||||
|
return $expense;
|
||||||
|
}
|
||||||
|
}
|
@ -124,9 +124,9 @@ class ExpenseCategoryController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function create(CreateExpenseCategoryRequest $request)
|
public function create(CreateExpenseCategoryRequest $request)
|
||||||
{
|
{
|
||||||
$tax_rate = ExpenseCategoryFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
$expense_category = ExpenseCategoryFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||||
|
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,11 +137,11 @@ class ExpenseCategoryController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function store(StoreExpenseCategoryRequest $request)
|
public function store(StoreExpenseCategoryRequest $request)
|
||||||
{
|
{
|
||||||
$tax_rate = ExpenseCategoryFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
$expense_category = ExpenseCategoryFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||||
$tax_rate->fill($request->all());
|
$expense_category->fill($request->all());
|
||||||
$tax_rate->save();
|
$expense_category->save();
|
||||||
|
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,9 +192,9 @@ class ExpenseCategoryController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function show(ShowExpenseCategoryRequest $request, ExpenseCategory $tax_rate)
|
public function show(ShowExpenseCategoryRequest $request, ExpenseCategory $expense_category)
|
||||||
{
|
{
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,9 +245,9 @@ class ExpenseCategoryController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function edit(EditExpenseCategoryRequest $request, ExpenseCategory $tax_rate)
|
public function edit(EditExpenseCategoryRequest $request, ExpenseCategory $expense_category)
|
||||||
{
|
{
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,12 +300,12 @@ class ExpenseCategoryController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function update(UpdateExpenseCategoryRequest $request, ExpenseCategory $tax_rate)
|
public function update(UpdateExpenseCategoryRequest $request, ExpenseCategory $expense_category)
|
||||||
{
|
{
|
||||||
$tax_rate->fill($request->all());
|
$expense_category->fill($request->all());
|
||||||
$tax_rate->save();
|
$expense_category->save();
|
||||||
|
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,13 +355,13 @@ class ExpenseCategoryController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function destroy(DestroyExpenseCategoryRequest $request, ExpenseCategory $tax_rate)
|
public function destroy(DestroyExpenseCategoryRequest $request, ExpenseCategory $expense_category)
|
||||||
{
|
{
|
||||||
$tax_rate->is_deleted = true;
|
$expense_category->is_deleted = true;
|
||||||
$tax_rate->save();
|
$expense_category->save();
|
||||||
$tax_rate->delete();
|
$expense_category->delete();
|
||||||
|
|
||||||
return $this->itemResponse($tax_rate);
|
return $this->itemResponse($expense_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -424,9 +424,9 @@ class ExpenseCategoryController extends BaseController
|
|||||||
|
|
||||||
$expense_categories = ExpenseCategory::withTrashed()->find($this->transformKeys($ids));
|
$expense_categories = ExpenseCategory::withTrashed()->find($this->transformKeys($ids));
|
||||||
|
|
||||||
$expense_categories->each(function ($tax_rate, $key) use ($action) {
|
$expense_categories->each(function ($expense_category, $key) use ($action) {
|
||||||
if (auth()->user()->can('edit', $tax_rate)) {
|
if (auth()->user()->can('edit', $expense_category)) {
|
||||||
$this->base_repo->{$action}($tax_rate);
|
$this->base_repo->{$action}($expense_category);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
55
app/Transformers/ExpenseCategoryTransformer.php
Normal file
55
app/Transformers/ExpenseCategoryTransformer.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
use App\Models\ExpenseCategory;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class ExpenseCategoryTransformer.
|
||||||
|
*/
|
||||||
|
class ExpenseCategoryTransformer extends EntityTransformer
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $defaultIncludes = [
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $availableIncludes = [
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Expense $expense_category
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function transform(ExpenseCategory $expense_category)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->encodePrimaryKey($expense_category->id),
|
||||||
|
'user_id' => $this->encodePrimaryKey($expense_category->user_id),
|
||||||
|
'name' => (string) $expense_category->name ?: '',
|
||||||
|
'is_deleted' => (bool) $expense_category->is_deleted,
|
||||||
|
'updated_at' => (int) $expense_category->updated_at,
|
||||||
|
'archived_at' => (int) $expense_category->deleted_at,
|
||||||
|
'created_at' => (int) $expense_category->created_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user