mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-06 07:11:09 +00:00
chore(catalog,contacts): remove legacy-era catalog and contacts sources
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Http\Controllers;
|
||||
|
||||
use App\Domains\Catalog\Application\ItemService;
|
||||
use App\Domains\Catalog\Http\Requests\DeleteItemsRequest;
|
||||
use App\Domains\Catalog\Http\Requests\ItemsRequest;
|
||||
use App\Domains\Catalog\Http\Resources\ItemResource;
|
||||
use App\Domains\Catalog\Models\Item;
|
||||
use App\Domains\Taxation\Models\TaxType;
|
||||
use App\Platform\Http\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ItemsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ItemService $itemService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieve a list of existing Items.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('viewAny', Item::class);
|
||||
|
||||
$limit = $request->has('limit') ? $request->limit : 10;
|
||||
|
||||
$items = Item::whereCompany()
|
||||
->leftJoin('units', 'units.id', '=', 'items.unit_id')
|
||||
->applyFilters($request->all())
|
||||
->select('items.*', 'units.name as unit_name')
|
||||
->latest()
|
||||
->paginateData($limit);
|
||||
|
||||
return ItemResource::collection($items)
|
||||
->additional(['meta' => [
|
||||
'tax_types' => TaxType::whereCompany()
|
||||
->whereTransactionType(TaxType::TRANSACTION_TYPE_SALES)
|
||||
->latest()
|
||||
->get(),
|
||||
'item_total_count' => Item::whereCompany()->count(),
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Item.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(ItemsRequest $request)
|
||||
{
|
||||
$this->authorize('create', Item::class);
|
||||
|
||||
$item = $this->itemService->create(
|
||||
$request->validated(),
|
||||
$request->input('taxes', []),
|
||||
(int) $request->header('company'),
|
||||
(int) $request->user()->getAuthIdentifier(),
|
||||
);
|
||||
|
||||
return new ItemResource($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* get an existing Item.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Item $item)
|
||||
{
|
||||
$this->authorize('view', $item);
|
||||
|
||||
return new ItemResource($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing Item.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(ItemsRequest $request, Item $item)
|
||||
{
|
||||
$this->authorize('update', $item);
|
||||
|
||||
$item = $this->itemService->update(
|
||||
$item,
|
||||
$request->validated(),
|
||||
$request->input('taxes', []),
|
||||
(int) $request->header('company'),
|
||||
);
|
||||
|
||||
return new ItemResource($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a list of existing Items.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(DeleteItemsRequest $request)
|
||||
{
|
||||
$this->authorize('delete multiple items');
|
||||
|
||||
$ids = Item::whereCompany()
|
||||
->whereIn('id', $request->ids)
|
||||
->pluck('id');
|
||||
|
||||
Item::destroy($ids);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user