From 3884a54539bb69043d2566e83c7259e4b5a9a254 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 6 Feb 2025 11:53:40 +0100 Subject: [PATCH] Store time ranges for index sites. --- app/Http/Controllers/Api/IncomingController.php | 4 ++++ app/Http/Controllers/Api/InvoiceController.php | 4 ++++ app/Http/Controllers/Api/PaymentController.php | 4 ++++ app/Http/Controllers/IncomingController.php | 16 +++++++++++++++- app/Http/Controllers/InvoiceController.php | 15 ++++++++++++++- app/Http/Controllers/PaymentController.php | 15 ++++++++++++++- resources/views/incoming/index.blade.php | 4 ++-- resources/views/invoice/index.blade.php | 4 ++-- resources/views/payment/index.blade.php | 4 ++-- 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/IncomingController.php b/app/Http/Controllers/Api/IncomingController.php index 53f8eac..ef3cc09 100644 --- a/app/Http/Controllers/Api/IncomingController.php +++ b/app/Http/Controllers/Api/IncomingController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Models\Incoming; use App\Models\Incomingitem; use App\Models\Incomingtax; +use App\Models\Option; use App\Models\Supplier; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; @@ -17,6 +18,9 @@ class IncomingController extends Controller */ public function index($from = null, $end = null): JsonResponse { + Option::updateOrCreate(['name' => 'incoming_from'], ['value' => $from]); + Option::updateOrCreate(['name' => 'incoming_end'], ['value' => $end]); + return response()->json(Incoming::whereBetween('issue_date', [$from, $end])->with(['supplier'])->orderBy('issue_date', 'desc')->get()); } diff --git a/app/Http/Controllers/Api/InvoiceController.php b/app/Http/Controllers/Api/InvoiceController.php index 8ebc652..a70cef3 100644 --- a/app/Http/Controllers/Api/InvoiceController.php +++ b/app/Http/Controllers/Api/InvoiceController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api; use App\Enum\InvoiceTypeCode; use App\Http\Controllers\Controller; use App\Models\Invoice; +use App\Models\Option; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Validation\Rule; @@ -16,6 +17,9 @@ class InvoiceController extends Controller */ public function index($from = null, $end = null): JsonResponse { + Option::updateOrCreate(['name' => 'invoice_from'], ['value' => $from]); + Option::updateOrCreate(['name' => 'invoice_end'], ['value' => $end]); + $from = $from . ' 00:00:00'; $end = $end . ' 23:59:59'; return response()->json(Invoice::whereBetween('created_at', [$from, $end])->with(['address', 'customer'])->orderBy('created_at', 'desc')->get()); diff --git a/app/Http/Controllers/Api/PaymentController.php b/app/Http/Controllers/Api/PaymentController.php index 1f1928a..96b80ab 100644 --- a/app/Http/Controllers/Api/PaymentController.php +++ b/app/Http/Controllers/Api/PaymentController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use App\Models\Invoice; +use App\Models\Option; use App\Models\Payment; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -15,6 +16,9 @@ class PaymentController extends Controller */ public function indexFilter($from = null, $end = null): JsonResponse { + Option::updateOrCreate(['name' => 'payment_from'], ['value' => $from]); + Option::updateOrCreate(['name' => 'payment_end'], ['value' => $end]); + return response()->json(Payment::whereBetween('payment_date', [$from, $end])->with(['invoice'])->orderBy('payment_date', 'desc')->get()); } diff --git a/app/Http/Controllers/IncomingController.php b/app/Http/Controllers/IncomingController.php index 966ea82..210216c 100644 --- a/app/Http/Controllers/IncomingController.php +++ b/app/Http/Controllers/IncomingController.php @@ -3,7 +3,9 @@ namespace App\Http\Controllers; use App\Models\Incoming; +use App\Models\Option; use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\Date; class IncomingController extends Controller { @@ -12,7 +14,19 @@ class IncomingController extends Controller */ public function index(): View { - return view('incoming.index'); + if (Option::where('name', '=', 'incoming_from')->count() > 0) { + $first = Option::where('name', '=', 'incoming_from')->first()->value; + } else { + $first = Date::now()->firstOfMonth()->format('Y-m-d'); + } + + if (Option::where('name', '=', 'incoming_end')->count() > 0) { + $last = Option::where('name', '=', 'incoming_end')->first()->value; + } else { + $last = Date::now()->format('Y-m-d'); + } + + return view('incoming.index', ['first' => $first, 'last' => $last]); } /** diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 60373ea..4c1259b 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Http\Option; use App\Models\Invoice; use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\Date; class InvoiceController extends Controller { @@ -13,7 +14,19 @@ class InvoiceController extends Controller */ public function index(): View { - return view('invoice.index'); + if (\App\Models\Option::where('name', '=', 'invoice_from')->count() > 0) { + $first = \App\Models\Option::where('name', '=', 'invoice_from')->first()->value; + } else { + $first = Date::now()->firstOfMonth()->format('Y-m-d'); + } + + if (\App\Models\Option::where('name', '=', 'invoice_end')->count() > 0) { + $last = \App\Models\Option::where('name', '=', 'invoice_end')->first()->value; + } else { + $last = Date::now()->format('Y-m-d'); + } + + return view('invoice.index', ['first' => $first, 'last' => $last]); } /** diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 7c12039..b0e5cf7 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers; +use App\Models\Option; use App\Models\Payment; use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\Date; class PaymentController extends Controller { @@ -12,7 +14,18 @@ class PaymentController extends Controller */ public function index(): View { - return view('payment.index'); + if (Option::where('name', '=', 'payment_from')->count() > 0) { + $first = Option::where('name', '=', 'payment_from')->first()->value; + } else { + $first = Date::now()->firstOfMonth()->format('Y-m-d'); + } + + if (Option::where('name', '=', 'payment_end')->count() > 0) { + $last = Option::where('name', '=', 'payment_end')->first()->value; + } else { + $last = Date::now()->format('Y-m-d'); + } + return view('payment.index', ['first' => $first, 'last' => $last]); } /** diff --git a/resources/views/incoming/index.blade.php b/resources/views/incoming/index.blade.php index 76b7bd9..ad4265c 100644 --- a/resources/views/incoming/index.blade.php +++ b/resources/views/incoming/index.blade.php @@ -104,8 +104,8 @@ net: 0, gross: 0, tax: 0, - from: "{{ \Illuminate\Support\Facades\Date::now()->firstOfMonth()->format('Y-m-d') }}", - end: "{{ \Illuminate\Support\Facades\Date::now()->format('Y-m-d') }}", + from: "{{ $first }}", + end: "{{ $last }}", invoices: [], init() { diff --git a/resources/views/invoice/index.blade.php b/resources/views/invoice/index.blade.php index bf74872..6361cc0 100644 --- a/resources/views/invoice/index.blade.php +++ b/resources/views/invoice/index.blade.php @@ -89,8 +89,8 @@