Extend invoices and invoice items to keep more information.
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Enum\InvoiceTypeCode;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
@@ -36,16 +38,21 @@ class InvoiceController extends Controller
|
||||
'customer_id' => 'required|integer|exists:customers,id',
|
||||
'address_id' => 'required|integer|exists:addresses,id',
|
||||
'delivery_id' => 'nullable|integer|exists:addresses,id',
|
||||
'project_id' => 'nullable|integer|exists:projects,id',
|
||||
'currency_code' => 'required|string',
|
||||
'type' => [Rule::enum(InvoiceTypeCode::class)],
|
||||
'project_count' => 'nullable|integer',
|
||||
'tax' => 'required|numeric',
|
||||
'sum' => 'required|numeric',
|
||||
'due_date' => 'required|date',
|
||||
'cash_discount' => 'nullable|numeric',
|
||||
'cash_discount_date' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$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();
|
||||
|
||||
@@ -63,6 +70,9 @@ class InvoiceController extends Controller
|
||||
'delivery_id' => 'nullable|integer|exists:addresses,id',
|
||||
'tax' => 'required|numeric',
|
||||
'sum' => 'required|numeric',
|
||||
'due_date' => 'required|date',
|
||||
'cash_discount' => 'nullable|numeric',
|
||||
'cash_discount_date' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$invoice->update($invoiceData);
|
||||
|
||||
@@ -31,6 +31,7 @@ class InvoiceitemController extends Controller
|
||||
'total' => 'required|numeric|min:0',
|
||||
'name' => 'required|string',
|
||||
'description' => 'nullable|string',
|
||||
'article_number' => 'nullable|string',
|
||||
|
||||
]);
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ class EController extends Controller
|
||||
if (!isset($taxes[$item->tax])) {
|
||||
$taxes[$item->tax] = ['tax' => 0, 'taxable' => 0];
|
||||
}
|
||||
$taxes[$item->tax]['tax'] += round($item->price * $item->amount * $item->tax / 100, 2, PHP_ROUND_HALF_UP);
|
||||
$taxes[$item->tax]['taxable'] += $item->price * $item->amount;
|
||||
$taxes[$item->tax]['tax'] += round($item->price * $item->amount * ($item->tax / 100) * (100 - $item->discount) / 100, 2, PHP_ROUND_HALF_UP);
|
||||
$taxes[$item->tax]['taxable'] += $item->price * $item->amount * (100 - $item->discount) / 100;
|
||||
}
|
||||
|
||||
return $taxes;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Option;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
@@ -20,7 +21,7 @@ class InvoiceController extends Controller
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('invoice.create');
|
||||
return view('invoice.create', ['options' => Option::optionsAsObject()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user