Optimise invoice data requests #56
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user