First invoice implementation.
This commit is contained in:
70
app/Http/Controllers/Api/InvoiceController.php
Normal file
70
app/Http/Controllers/Api/InvoiceController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index($from = null, $end = null): JsonResponse
|
||||
{
|
||||
$from = $from . ' 00:00:00';
|
||||
$end = $end . ' 23:59:59';
|
||||
return response()->json(Invoice::whereBetween('created_at', [$from, $end])->with('address')->orderBy('created_at', 'desc')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$invoiceData = $request->validate([
|
||||
'customer_id' => 'required|integer|exists:customers,id',
|
||||
'address_id' => 'required|integer|exists:addresses,id',
|
||||
'delivery_id' => 'nullable|integer|exists:addresses,id',
|
||||
'tax' => 'required|numeric',
|
||||
'sum' => 'required|numeric',
|
||||
]);
|
||||
$invoiceData['user_id'] = auth()->id();
|
||||
$invoiceData['type'] = '380';
|
||||
$invoiceData['status'] = 'created';
|
||||
$invoiceData['invoice_number'] = Invoice::whereYear('created_at', now()->year)->count() + 1;
|
||||
|
||||
|
||||
|
||||
$invoice = new Invoice($invoiceData);
|
||||
$invoice->save();
|
||||
|
||||
return response()->json($invoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Invoice $invoice)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Invoice $invoice)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
64
app/Http/Controllers/Api/InvoiceitemController.php
Normal file
64
app/Http/Controllers/Api/InvoiceitemController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Invoiceitem;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceitemController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Invoice $invoice): JsonResponse
|
||||
{
|
||||
return response()->json($invoice->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request, Invoice $invoice): JsonResponse
|
||||
{
|
||||
$itemData = $request->validate([
|
||||
'amount' => 'required|numeric|min:0',
|
||||
'discount' => 'numeric|nullable',
|
||||
'tax' => 'required|numeric|min:0',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'total' => 'required|numeric|min:0',
|
||||
'name' => 'required|string',
|
||||
'description' => 'nullable|string',
|
||||
|
||||
]);
|
||||
|
||||
$item = $invoice->items()->create($itemData);
|
||||
return response()->json($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Invoiceitem $invoiceitem)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Invoiceitem $invoiceitem)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Invoiceitem $invoiceitem)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user