From d01b7d6db1fb8a2aa0b5c3633abd4589d14e286c Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Sun, 27 Jul 2025 15:58:11 +0330 Subject: [PATCH] create setad report tables --- .env.example | 6 ++ .../CumulativeCentersStatsController.php | 53 ++++++++++++++--- .../CumulativeKeypressStatsController.php | 57 ++++++++++++++++--- ...CumulativeMessageRatingStatsController.php | 51 +++++++++++++++++ .../CumulativeVoiceRatingStatsController.php | 35 +++++++++--- app/Models/Cdr.php | 10 ++++ config/database.php | 19 +++++++ .../CountryMessageRatingReportFactory.php | 15 +++-- .../CountryVoiceRatingReportFactory.php | 6 +- ...ate_country_voice_rating_reports_table.php | 6 +- ...e_country_message_rating_reports_table.php | 15 +++-- routes/web.php | 9 +++ 12 files changed, 241 insertions(+), 41 deletions(-) create mode 100644 app/Http/Controllers/Setad/CumulativeMessageRatingStatsController.php create mode 100644 app/Models/Cdr.php diff --git a/.env.example b/.env.example index d6e8d17..e3d6ee7 100644 --- a/.env.example +++ b/.env.example @@ -27,6 +27,12 @@ DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= +ASTERISK_DB_HOST= +ASTERISK_DB_PORT= +ASTERISK_DB_DATABASE= +ASTERISK_DB_USERNAME= +ASTERISK_DB_PASSWORD= + SESSION_DRIVER=database SESSION_LIFETIME=120 SESSION_ENCRYPT=false diff --git a/app/Http/Controllers/Setad/CumulativeCentersStatsController.php b/app/Http/Controllers/Setad/CumulativeCentersStatsController.php index 6cea4ba..452c218 100644 --- a/app/Http/Controllers/Setad/CumulativeCentersStatsController.php +++ b/app/Http/Controllers/Setad/CumulativeCentersStatsController.php @@ -4,20 +4,59 @@ namespace App\Http\Controllers\Setad; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use app\Http\Traits\ApiResponse; use App\Models\CountryCallsReport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class CumulativeCentersStatsController extends Controller { + use ApiResponse; + public function index(Request $request): JsonResponse { - $data = DataTableFacade::run( - CountryCallsReport::query(), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - ); - return response()->json($data); + $data = DB::select(" + SELECT + province_id, + province_name, + SUM(total) as total, + SUM(route_to_teh4) as route_to_teh4, + SUM(route_to_teh5) as route_to_teh5, + SUM(route_to_os4) as route_to_os4, + SUM(route_to_os5) as route_to_os5, + SUM(answered) as answered, + SUM(answered_over10) as answered_over10, + SUM(missed) as missed, + SUM(dnd) as dnd, + SUM(transferred) as transferred, + SUM(talked_to_operator) as talked_to_operator, + AVG(average_calls_time) as average_calls_time, + SUM(fails) as fails + FROM country_calls_reports + 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) + FROM country_calls_reports + "); + + return $this->successResponse($data); } } diff --git a/app/Http/Controllers/Setad/CumulativeKeypressStatsController.php b/app/Http/Controllers/Setad/CumulativeKeypressStatsController.php index 47cdec0..ad6852c 100644 --- a/app/Http/Controllers/Setad/CumulativeKeypressStatsController.php +++ b/app/Http/Controllers/Setad/CumulativeKeypressStatsController.php @@ -4,20 +4,63 @@ namespace App\Http\Controllers\Setad; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use app\Http\Traits\ApiResponse; use App\Models\CountryKeypressReport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class CumulativeKeypressStatsController extends Controller { + use ApiResponse; + public function index(Request $request): JsonResponse { - $data = DataTableFacade::run( - CountryKeypressReport::query(), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - ); - return response()->json($data); + $data = DB::select(" + SELECT + province_id, + province_name, + SUM(total) as total, + SUM(key1) as key1, + SUM(key2) as key2, + SUM(key3) as key3, + SUM(key4) as key4, + SUM(key5) as key5, + SUM(key6) as key6, + SUM(key9) as key9, + SUM(key4_1) as key4_1, + SUM(key4_2) as key4_2, + SUM(key5_1) as key5_1, + SUM(key5_2) as key5_2, + SUM(key2_1) as key2_1, + SUM(key2_2) as key2_2, + SUM(key2_3) as key2_3 + FROM country_keypress_reports + 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) + FROM country_keypress_reports + "); + + return $this->successResponse($data); } } diff --git a/app/Http/Controllers/Setad/CumulativeMessageRatingStatsController.php b/app/Http/Controllers/Setad/CumulativeMessageRatingStatsController.php new file mode 100644 index 0000000..956cc87 --- /dev/null +++ b/app/Http/Controllers/Setad/CumulativeMessageRatingStatsController.php @@ -0,0 +1,51 @@ +successResponse($data); + } +} diff --git a/app/Http/Controllers/Setad/CumulativeVoiceRatingStatsController.php b/app/Http/Controllers/Setad/CumulativeVoiceRatingStatsController.php index 15802b4..0a7f247 100644 --- a/app/Http/Controllers/Setad/CumulativeVoiceRatingStatsController.php +++ b/app/Http/Controllers/Setad/CumulativeVoiceRatingStatsController.php @@ -4,20 +4,41 @@ namespace App\Http\Controllers\Setad; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; +use app\Http\Traits\ApiResponse; use App\Models\CountryVoiceRatingReport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class CumulativeVoiceRatingStatsController extends Controller { + use ApiResponse; + public function index(Request $request): JsonResponse { - $data = DataTableFacade::run( - CountryVoiceRatingReport::query(), - $request, - allowedFilters: ['*'], - allowedSortings: ['*'], - ); - return response()->json($data); + $data = DB::select(" + 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 + FROM country_voice_rating_reports + GROUP BY province_id, province_name + + UNION ALL + + SELECT + 0 as province_id, + 'کشوری' as province_name, + SUM(message_quality_ok), + SUM(message_format_ok), + SUM(message_quality_nok), + SUM(message_format_nok) + FROM country_voice_rating_reports + "); + + return $this->successResponse($data); } } diff --git a/app/Models/Cdr.php b/app/Models/Cdr.php new file mode 100644 index 0000000..cad9a3a --- /dev/null +++ b/app/Models/Cdr.php @@ -0,0 +1,10 @@ + env('DB_TRUST_SERVER_CERTIFICATE', 'false'), ], + 'asterisk' => [ + 'driver' => 'mysql', + 'url' => env('DB_URL'), + 'host' => env('ASTERISK_DB_HOST', '127.0.0.1'), + 'port' => env('ASTERISK_DB_PORT', '3306'), + 'database' => env('ASTERISK_DB_DATABASE', 'laravel'), + 'username' => env('ASTERISK_DB_USERNAME', 'root'), + 'password' => env('ASTERISK_DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => env('DB_CHARSET', 'utf8mb4'), + 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], ], /* diff --git a/database/factories/CountryMessageRatingReportFactory.php b/database/factories/CountryMessageRatingReportFactory.php index 475dd76..65b3f55 100644 --- a/database/factories/CountryMessageRatingReportFactory.php +++ b/database/factories/CountryMessageRatingReportFactory.php @@ -24,12 +24,15 @@ class CountryMessageRatingReportFactory extends Factory return Province::query()->find($attributes['province_id'])->name; }, 'date' => $this->faker->date(), - 'very_good' => $this->faker->numberBetween(10, 100), - 'good' => $this->faker->numberBetween(10, 100), - 'average' => $this->faker->numberBetween(10, 100), - 'bad' => $this->faker->numberBetween(10, 100), - 'very_bad' => $this->faker->numberBetween(10, 100), - 'wrong_code' => $this->faker->numberBetween(10, 100), + 'total' => $this->faker->numberBetween(100, 1000), + 'listens' => $this->faker->numberBetween(10, 100), + 'not_listens' => $this->faker->numberBetween(10, 100), + 'review_average' => $this->faker->numberBetween(10, 100), + 'action1' => $this->faker->numberBetween(10, 100), + 'action2' => $this->faker->numberBetween(10, 100), + 'action3' => $this->faker->numberBetween(10, 100), + 'action4' => $this->faker->numberBetween(10, 100), + 'action5' => $this->faker->numberBetween(10, 100), ]; } } diff --git a/database/factories/CountryVoiceRatingReportFactory.php b/database/factories/CountryVoiceRatingReportFactory.php index e794741..544e34b 100644 --- a/database/factories/CountryVoiceRatingReportFactory.php +++ b/database/factories/CountryVoiceRatingReportFactory.php @@ -24,12 +24,10 @@ class CountryVoiceRatingReportFactory extends Factory return Province::query()->find($attributes['province_id'])->name; }, 'date' => $this->faker->date(), - 'voice_quality_ok' => $this->faker->numberBetween(10, 100), 'message_quality_ok' => $this->faker->numberBetween(10, 100), - 'voice_format_ok' => $this->faker->numberBetween(10, 100), - 'voice_quality_nok' => $this->faker->numberBetween(10, 100), + 'message_format_ok' => $this->faker->numberBetween(10, 100), 'message_quality_nok' => $this->faker->numberBetween(10, 100), - 'voice_format_nok' => $this->faker->numberBetween(10, 100), + 'message_format_nok' => $this->faker->numberBetween(10, 100), ]; } } diff --git a/database/migrations/2025_07_21_062738_create_country_voice_rating_reports_table.php b/database/migrations/2025_07_21_062738_create_country_voice_rating_reports_table.php index b31a6c5..ad54226 100644 --- a/database/migrations/2025_07_21_062738_create_country_voice_rating_reports_table.php +++ b/database/migrations/2025_07_21_062738_create_country_voice_rating_reports_table.php @@ -16,12 +16,10 @@ return new class extends Migration $table->foreignId('province_id')->constrained('provinces'); $table->string('province_name'); $table->date('date'); - $table->integer('voice_quality_ok'); $table->integer('message_quality_ok'); - $table->integer('voice_format_ok'); - $table->integer('voice_quality_nok'); + $table->integer('message_format_ok'); $table->integer('message_quality_nok'); - $table->integer('voice_format_nok'); + $table->integer('message_format_nok'); $table->timestamps(); }); } diff --git a/database/migrations/2025_07_21_072211_create_country_message_rating_reports_table.php b/database/migrations/2025_07_21_072211_create_country_message_rating_reports_table.php index 1f92bfb..3c8604f 100644 --- a/database/migrations/2025_07_21_072211_create_country_message_rating_reports_table.php +++ b/database/migrations/2025_07_21_072211_create_country_message_rating_reports_table.php @@ -16,12 +16,15 @@ return new class extends Migration $table->foreignId('province_id')->constrained('provinces'); $table->string('province_name'); $table->date('date'); - $table->integer('very_good'); - $table->integer('good'); - $table->integer('average'); - $table->integer('bad'); - $table->integer('very_bad'); - $table->integer('wrong_code'); + $table->integer('total'); + $table->integer('listens'); + $table->integer('not_listens'); + $table->float('review_average'); + $table->integer('action1'); + $table->integer('action2'); + $table->integer('action3'); + $table->integer('action4'); + $table->integer('action5'); $table->timestamps(); }); } diff --git a/routes/web.php b/routes/web.php index 371e4fe..23f0dab 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProvinceController; use App\Http\Controllers\Setad\CumulativeCentersStatsController; use App\Http\Controllers\Setad\CumulativeKeypressStatsController; +use App\Http\Controllers\Setad\CumulativeMessageRatingStatsController; use App\Http\Controllers\Setad\CumulativeVoiceRatingStatsController; use App\Http\Middleware\SuperAdminCheck; use Illuminate\Support\Facades\Route; @@ -119,4 +120,12 @@ Route::prefix('server')->group(function () { ->group(function () { Route::get('/', 'index')->name('index'); }); + + Route::middleware('auth') + ->prefix('cumulative_message_ratings') + ->name('cumulativeMessageRatings.') + ->controller(CumulativeMessageRatingStatsController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + }); });