Add products module #46

This commit is contained in:
2025-11-26 10:05:43 +01:00
parent 914613e3ea
commit c55fc78c36
21 changed files with 607 additions and 50 deletions
+10 -2
View File
@@ -9,13 +9,21 @@ class LineItemController extends Controller
{
public function index($invoiceId)
{
$items = LineItem::select()
$items = LineItem::with('unit')
->select('line_items.*')
->where('invoice_id', $invoiceId)
->orderBy('position', 'desc')
->get();
return $items->map(function ($item) {
return ApiDataTransformer::snakeToCamel($item->toArray());
$itemArray = $item->toArray();
if ($item->unit) {
$itemArray['unit_name'] = $item->unit->name;
$itemArray['unit_symbol'] = $item->unit->symbol;
}
return ApiDataTransformer::snakeToCamel($itemArray);
});
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers;
use App\Models\ProductCategory;
use Illuminate\Http\Request;
class ProductCategoryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(ProductCategory $productCategory)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(ProductCategory $productCategory)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, ProductCategory $productCategory)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(ProductCategory $productCategory)
{
//
}
}
@@ -0,0 +1,78 @@
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
use App\Support\ApiDataTransformer;
use Inertia\Inertia;
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*/
public function show()
{
return Inertia::render(
'Products',
['productsData' => $this->index()]
);
}
/**
* Display a listing of the resource.
*/
public function index()
{
$products = Product::with(['category', 'unit'])->orderBy('title', 'asc')->get();
return ApiDataTransformer::snakeToCamel($products->toArray());
}
public function single($id)
{
$products = Product::with(['category', 'unit'])->findOrFail($id);
return ApiDataTransformer::snakeToCamel($products->toArray());
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Product $product)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Product $product)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Product $product)
{
//
}
}