From 21f573e18443a38c57ee35a2d7b5020ce01759f1 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Mon, 28 Jul 2025 14:08:56 +0330 Subject: [PATCH] use builder for query --- .../CumulativeCentersStatsController.php | 48 ++++++++++--------- .../CumulativeKeypressStatsController.php | 45 ++++++++--------- ...CumulativeMessageRatingStatsController.php | 11 ++--- .../CumulativeVoiceRatingStatsController.php | 11 ++--- .../Admin/UserManagement/StoreRequest.php | 2 +- 5 files changed, 55 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/HeadquartersDashboard/CumulativeCentersStatsController.php b/app/Http/Controllers/HeadquartersDashboard/CumulativeCentersStatsController.php index 6c3ffdf..70141c6 100644 --- a/app/Http/Controllers/HeadquartersDashboard/CumulativeCentersStatsController.php +++ b/app/Http/Controllers/HeadquartersDashboard/CumulativeCentersStatsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\HeadquartersDashboard; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use App\Models\CountryCallsReport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -12,8 +13,8 @@ class CumulativeCentersStatsController extends Controller { public function index(Request $request): JsonResponse { - $query = DB::table('country_calls_reports')->selectRaw(" - SELECT + $query = DB::table('country_calls_reports') + ->selectRaw(" province_id, province_name, SUM(total) as total, @@ -29,27 +30,28 @@ class CumulativeCentersStatsController extends Controller SUM(talked_to_operator) as talked_to_operator, AVG(average_calls_time) as average_calls_time, SUM(fails) as fails - GROUP BY province_id, province_name - - UNION ALL - - SELECT - 0 as province_id, - 'کشور' as province_name, - SUM(total), - SUM(route_to_teh4), - SUM(route_to_teh5), - SUM(route_to_os4), - SUM(route_to_os5), - SUM(answered), - SUM(answered_over10), - SUM(missed), - SUM(dnd), - SUM(transferred), - SUM(talked_to_operator), - AVG(average_calls_time), - SUM(fails) - "); + ") + ->groupBy('province_id', 'province_name') + ->unionAll( + DB::table('country_calls_reports') + ->selectRaw(" + 0 as province_id, + 'کشوری' as province_name, + SUM(total), + SUM(route_to_teh4), + SUM(route_to_teh5), + SUM(route_to_os4), + SUM(route_to_os5), + SUM(answered), + SUM(answered_over10), + SUM(missed), + SUM(dnd), + SUM(transferred), + SUM(talked_to_operator), + AVG(average_calls_time), + SUM(fails) + ") + ); return response()->json( DataTableFacade::run( diff --git a/app/Http/Controllers/HeadquartersDashboard/CumulativeKeypressStatsController.php b/app/Http/Controllers/HeadquartersDashboard/CumulativeKeypressStatsController.php index 5f0043f..805f6e1 100644 --- a/app/Http/Controllers/HeadquartersDashboard/CumulativeKeypressStatsController.php +++ b/app/Http/Controllers/HeadquartersDashboard/CumulativeKeypressStatsController.php @@ -13,7 +13,6 @@ class CumulativeKeypressStatsController extends Controller public function index(Request $request): JsonResponse { $query = DB::table('country_keypress_reports')->selectRaw(" - SELECT province_id, province_name, SUM(total) as total, @@ -31,29 +30,27 @@ class CumulativeKeypressStatsController extends Controller SUM(key2_1) as key2_1, SUM(key2_2) as key2_2, SUM(key2_3) as key2_3 - GROUP BY province_id, province_name - - UNION ALL - - SELECT - 0 as province_id, - 'کشوری' as province_name, - SUM(total), - SUM(key1), - SUM(key2), - SUM(key3), - SUM(key4), - SUM(key5), - SUM(key6), - SUM(key9), - SUM(key4_1), - SUM(key4_2), - SUM(key5_1), - SUM(key5_2), - SUM(key2_1), - SUM(key2_2), - SUM(key2_3) - "); + ") + ->groupBy('province_id', 'province_name') + ->unionAll(DB::table('country_keypress_reports')->selectRaw(" + 0 as province_id, + 'کشوری' as province_name, + SUM(total), + SUM(key1), + SUM(key2), + SUM(key3), + SUM(key4), + SUM(key5), + SUM(key6), + SUM(key9), + SUM(key4_1), + SUM(key4_2), + SUM(key5_1), + SUM(key5_2), + SUM(key2_1), + SUM(key2_2), + SUM(key2_3) + ")); return response()->json( DataTableFacade::run( diff --git a/app/Http/Controllers/HeadquartersDashboard/CumulativeMessageRatingStatsController.php b/app/Http/Controllers/HeadquartersDashboard/CumulativeMessageRatingStatsController.php index 6135863..12b60de 100644 --- a/app/Http/Controllers/HeadquartersDashboard/CumulativeMessageRatingStatsController.php +++ b/app/Http/Controllers/HeadquartersDashboard/CumulativeMessageRatingStatsController.php @@ -14,7 +14,6 @@ class CumulativeMessageRatingStatsController extends Controller public function index(Request $request): JsonResponse { $query = DB::table('country_message_rating_reports')->selectRaw(" - SELECT province_id, province_name, SUM(total) as total, @@ -26,11 +25,9 @@ class CumulativeMessageRatingStatsController extends Controller SUM(action3) as action3, SUM(action4) as action4, SUM(action5) as action5 - GROUP BY province_id, province_name - - UNION ALL - - SELECT + ") + ->groupBy('province_id', 'province_name') + ->unionAll(DB::table('country_message_rating_reports')->selectRaw(" 0 as province_id, 'کشوری' as province_name, SUM(total), @@ -42,7 +39,7 @@ class CumulativeMessageRatingStatsController extends Controller SUM(action3), SUM(action4), SUM(action5) - "); + ")); return response()->json( DataTableFacade::run( diff --git a/app/Http/Controllers/HeadquartersDashboard/CumulativeVoiceRatingStatsController.php b/app/Http/Controllers/HeadquartersDashboard/CumulativeVoiceRatingStatsController.php index 1c5d7ff..f5008cd 100644 --- a/app/Http/Controllers/HeadquartersDashboard/CumulativeVoiceRatingStatsController.php +++ b/app/Http/Controllers/HeadquartersDashboard/CumulativeVoiceRatingStatsController.php @@ -13,25 +13,22 @@ class CumulativeVoiceRatingStatsController extends Controller public function index(Request $request): JsonResponse { $query = DB::table('country_voice_rating_reports')->selectRaw(" - SELECT province_id, province_name, SUM(message_quality_ok) as message_quality_ok, SUM(message_format_ok) as message_format_ok, SUM(message_quality_nok) as message_quality_nok, SUM(message_format_nok) as message_format_nok - GROUP BY province_id, province_name - - UNION ALL - - SELECT + ") + ->groupBy('province_id', 'province_name') + ->unionAll(DB::table('country_voice_rating_reports')->selectRaw(" 0 as province_id, 'کشوری' as province_name, SUM(message_quality_ok), SUM(message_format_ok), SUM(message_quality_nok), SUM(message_format_nok) - "); + ")); return response()->json( DataTableFacade::run( diff --git a/app/Http/Requests/Admin/UserManagement/StoreRequest.php b/app/Http/Requests/Admin/UserManagement/StoreRequest.php index cc34bdb..b47db05 100644 --- a/app/Http/Requests/Admin/UserManagement/StoreRequest.php +++ b/app/Http/Requests/Admin/UserManagement/StoreRequest.php @@ -26,7 +26,7 @@ class StoreRequest extends FormRequest 'full_name' => 'required|max:255|string', 'username' => 'required|unique:users,username|string', 'position' => 'required', - 'gender' => 'required|in:1,2', + 'gender' => 'required|in:male,female', 'national_id' => 'required|digits:10|unique:users,national_id', 'phone_number' => 'required|numeric|digits:11|unique:users,phone_number|regex:/^09\d{9}$/', 'province_id' => 'required|exists:provinces,id',