Optimise invoice data requests #56
This commit is contained in:
@@ -2,12 +2,20 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Models\Customer;
|
||||
use App\Support\ApiDataTransformer;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
public function show()
|
||||
{
|
||||
return Inertia::render('Customers', [
|
||||
'customersData' => $this->index()
|
||||
]);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$customers = Customer::with(['contacts' => function ($query) {
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use App\Models\Invoice;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use horstoeko\zugferdlaravel\Facades\ZugferdLaravel;
|
||||
use horstoeko\zugferd\codelists\ZugferdInvoiceType;
|
||||
// use horstoeko\zugferd\codelists\ZugferdInvoiceType;
|
||||
use horstoeko\zugferd\codelists\ZugferdUnitCodes;
|
||||
use horstoeko\zugferd\codelists\ZugferdVatCategoryCodes;
|
||||
use horstoeko\zugferd\codelists\ZugferdVatTypeCodes;
|
||||
@@ -19,10 +20,53 @@
|
||||
use App\Support\ApiDataTransformer;
|
||||
use DateTime;
|
||||
use tbQuar\Facades\Quar;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return Inertia::render('Invoices', ['invoicesData' => $this->summaryThisYear()]
|
||||
);
|
||||
}
|
||||
|
||||
public function summaryAll()
|
||||
{
|
||||
$invoices = Invoice::select()
|
||||
->orderBy('invoice_date', 'asc')
|
||||
->orderByRaw("CAST(SUBSTRING(nr, 4) AS UNSIGNED) ASC")
|
||||
->get();
|
||||
|
||||
return $invoices->map(function ($invoice) {
|
||||
return ApiDataTransformer::snakeToCamel($invoice->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
public function summaryThisYear()
|
||||
{
|
||||
$invoices = Invoice::select()
|
||||
->where('invoice_date', '>=', new DateTime('first day of january this year')->format('Y-m-d'))
|
||||
->orderBy('invoice_date', 'asc')
|
||||
->orderByRaw("CAST(SUBSTRING(nr, 4) AS UNSIGNED) ASC")
|
||||
->get();
|
||||
|
||||
return $invoices->map(function ($invoice) {
|
||||
return ApiDataTransformer::snakeToCamel($invoice->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
public function summaryBeforeThisYear()
|
||||
{
|
||||
$invoices = Invoice::select()
|
||||
->where('invoice_date', '<', new DateTime('first day of january this year')->format('Y-m-d'))
|
||||
->orderBy('invoice_date', 'asc')
|
||||
->orderByRaw("CAST(SUBSTRING(nr, 4) AS UNSIGNED) ASC")
|
||||
->get();
|
||||
|
||||
return $invoices->map(function ($invoice) {
|
||||
return ApiDataTransformer::snakeToCamel($invoice->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$invoices = Invoice::with([
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\LineItem;
|
||||
use App\Support\ApiDataTransformer;
|
||||
|
||||
class LineItemController extends Controller
|
||||
{
|
||||
public function index($invoiceId)
|
||||
{
|
||||
$items = LineItem::select()
|
||||
->where('invoice_id', $invoiceId)
|
||||
->orderBy('position', 'desc')
|
||||
->get();
|
||||
|
||||
return $items->map(function ($item) {
|
||||
return ApiDataTransformer::snakeToCamel($item->toArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user