debug the report tables
This commit is contained in:
26
app/Enums/AxisTypes.php
Normal file
26
app/Enums/AxisTypes.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum AxisTypes: int
|
||||
{
|
||||
case AZADRAH= 1;
|
||||
case BOZORGRAH = 2;
|
||||
case ASLI = 3;
|
||||
|
||||
case FARYI = 4;
|
||||
case ROSTAYI = 5;
|
||||
|
||||
public static function name(int $state): string
|
||||
{
|
||||
$mapArray = [
|
||||
1 => 'آزادراه',
|
||||
2 => 'بزرگراه',
|
||||
3 => 'اصلی',
|
||||
4 => 'فرعی',
|
||||
5 => 'روستایی',
|
||||
];
|
||||
|
||||
return $mapArray[$state];
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,22 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
$existedProvinces = array_keys($data['activities']);
|
||||
|
||||
foreach (\App\Models\Province::all() as $value) {
|
||||
$provinceId = $value->id;
|
||||
|
||||
if (!array_key_exists($provinceId, $existedProvinces)) {
|
||||
$data['activities'][] = [
|
||||
'province_id' => $provinceId,
|
||||
'name_fa' => $value->name_fa,
|
||||
'sum' => 0,
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Exports\V3\SafetyAndPrivacy;
|
||||
|
||||
use App\Models\EdarateShahri;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
@@ -14,11 +16,28 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
public function __construct(private array $data, Request $request){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
$existedCities = array_keys($data['activities']);
|
||||
$edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
foreach ($edarat as $value) {
|
||||
$edareId = $value->id;
|
||||
|
||||
if (!array_key_exists($edareId, $existedCities)) {
|
||||
$data['activities'][] = [
|
||||
'edare_shahri_id' => $edareId,
|
||||
'name_fa' => $value->name_fa,
|
||||
'sum' => 0,
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
|
||||
@@ -47,6 +47,6 @@ class SafetyAndPrivacyReportController extends Controller
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->provinceActivity($request);
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ProvinceActivityReport($data), $name);
|
||||
return Excel::download(new ProvinceActivityReport($data, $request), $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard;
|
||||
|
||||
use App\Enums\AxisTypes;
|
||||
use App\Exports\V3\SafetyAndPrivacy\CartableReport;
|
||||
use App\Facades\File\FileFacade;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -73,6 +74,8 @@ class SafetyAndPrivacyController extends Controller
|
||||
'edare_shahri_id' => $user->edarate_shahri_id,
|
||||
'edare_shahri_name' => $user->edarate_shahri_name,
|
||||
'way_id' => $nominatimService->get_way_id_from_nominatim($coordinates[0], $coordinates[1]),
|
||||
'axis_type_id' => $request->axis_type_id,
|
||||
'axis_type_name' => AxisTypes::name($request->axis_type_id),
|
||||
'step' => 1,
|
||||
'step_fa' => 'گام اول (شناسایی)'
|
||||
]);
|
||||
|
||||
@@ -27,6 +27,7 @@ class FirstStepStoreRequest extends FormRequest
|
||||
'activity_date' => 'required|date_format:Y-m-d',
|
||||
'activity_time' => 'required|date_format:H:i',
|
||||
'recognize_picture' => 'required|image',
|
||||
'axis_type_id' => 'required|integer|exists:axis_types,id',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
13
app/Models/AxisType.php
Normal file
13
app/Models/AxisType.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AxisType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -28,7 +28,14 @@ class SafetyAndPrivacy extends Model
|
||||
'edare_shahri_name',
|
||||
'way_id',
|
||||
'activity_date_time',
|
||||
|
||||
'step',
|
||||
'step_fa',
|
||||
'judiciary_document',
|
||||
'judiciary_document_upload_date',
|
||||
'action_picture',
|
||||
'action_picture_document_upload_date',
|
||||
'axis_type_id',
|
||||
'axis_type_name',
|
||||
];
|
||||
|
||||
public $table = "safety_and_privacy";
|
||||
|
||||
@@ -57,7 +57,7 @@ class SafetyAndPrivacyTableService
|
||||
$activities = [];
|
||||
|
||||
$country = DB::select(
|
||||
"SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step"
|
||||
"SELECT COUNT(*) as qty,info_id, step FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step"
|
||||
);
|
||||
|
||||
$countryTotalSum = 0;
|
||||
@@ -88,36 +88,30 @@ class SafetyAndPrivacyTableService
|
||||
$activities[] = $countryData;
|
||||
|
||||
$provinces = DB::select(
|
||||
"SELECT province_id, province_fa, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa"
|
||||
"SELECT province_id, province_fa, COUNT(*) as qty,info_id, step FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa"
|
||||
);
|
||||
|
||||
$provinceTotalSum = 0;
|
||||
$provinceData = [
|
||||
'89' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'90' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'91' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
];
|
||||
foreach ($provinces as $key => $value) {
|
||||
$provinceTotalSum += $value->qty;
|
||||
$provinceData[$value->info_id][$value->step] = $value->qty;
|
||||
$provinceData["sum"] = $provinceTotalSum;
|
||||
$provinceData["province_fa"] = $value->province_fa;
|
||||
$provinceData["province_id"] = $value->province_id;
|
||||
$activities[] = $provinceData;
|
||||
foreach ($provinces as $value) {
|
||||
$provinceId = $value->province_id;
|
||||
|
||||
// Check if the province already exists in the activities array
|
||||
if (!isset($activities[$provinceId])) {
|
||||
$activities[$provinceId] = (object) [
|
||||
'province_id' => $provinceId,
|
||||
'name_fa' => $value->province_fa,
|
||||
'sum' => 0,
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
];
|
||||
}
|
||||
|
||||
$activities[$provinceId]->{$value->info_id}[$value->step] = $value->qty;
|
||||
$activities[$provinceId]->sum += $value->qty;
|
||||
}
|
||||
|
||||
$activities = array_values($activities);
|
||||
|
||||
return [
|
||||
'activities' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
@@ -133,7 +127,7 @@ class SafetyAndPrivacyTableService
|
||||
$activities = [];
|
||||
|
||||
$province = DB::select('
|
||||
SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step
|
||||
SELECT COUNT(*) as qty,info_id, step FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step
|
||||
');
|
||||
|
||||
$provinceTotalSum = 0;
|
||||
@@ -158,42 +152,35 @@ class SafetyAndPrivacyTableService
|
||||
];
|
||||
foreach ($province as $key => $value) {
|
||||
$provinceTotalSum += $value->qty;
|
||||
$provinceData["info-".$value->info_id]["step-".$value->step] = $value->qty;
|
||||
$provinceData[$value->info_id][$value->step] = $value->qty;
|
||||
$provinceData["sum"] = $provinceTotalSum;
|
||||
}
|
||||
$activities[] = $provinceData;
|
||||
|
||||
$cities = DB::select('
|
||||
SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id
|
||||
SELECT edare_shahri_id, COUNT(*) as qty,info_id, step FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id
|
||||
');
|
||||
|
||||
$cityTotalSum = 0;
|
||||
$cityData = [
|
||||
'89' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'90' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'91' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
];
|
||||
foreach ($cities as $key => $value) {
|
||||
$cityTotalSum += $value->qty;
|
||||
$cityData[$value->info_id][$value->step] = $value->qty;
|
||||
$cityData["name_fa"] = \App\Models\EdarateShahri::query()->find($value->edare_shahri_id)->name_fa;
|
||||
$cityData["edare_shahri_id"] = $value->edare_shahri_id;
|
||||
$cityData["sum"] = $cityTotalSum;
|
||||
$activities[] = $cityData;
|
||||
foreach ($cities as $value) {
|
||||
$cityId = $value->edare_shahri_id;
|
||||
|
||||
// Initialize data for each unique city
|
||||
if (!isset($activities[$cityId])) {
|
||||
$activities[$cityId] = (object) [
|
||||
'edare_shahri_id' => $cityId,
|
||||
'name_fa' => \App\Models\EdarateShahri::query()->find($cityId)->name_fa,
|
||||
'sum' => 0,
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
];
|
||||
}
|
||||
$activities[$cityId]->{$value->info_id}[$value->step] = $value->qty;
|
||||
$activities[$cityId]->sum += $value->qty;
|
||||
}
|
||||
|
||||
$activities = array_values($activities);
|
||||
|
||||
return [
|
||||
'activities' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
|
||||
23
database/factories/AxisTypeFactory.php
Normal file
23
database/factories/AxisTypeFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AxisType>
|
||||
*/
|
||||
class AxisTypeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('axis_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('axis_types');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('safety_and_privacy', function (Blueprint $table) {
|
||||
$table->foreignId('axis_type_id')->nullable()->constrained('axis_types');
|
||||
$table->string('axis_type_name')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('safety_and_privacy', function (Blueprint $table) {
|
||||
$table->dropForeign('axis_type_id');
|
||||
$table->dropColumn('axis_type_name');
|
||||
});
|
||||
}
|
||||
};
|
||||
17
database/seeders/AxisTypeSeeder.php
Normal file
17
database/seeders/AxisTypeSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AxisTypeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -327,6 +327,7 @@ Route::prefix('safety_and_privacy')
|
||||
->controller(SafetyAndPrivacyController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
|
||||
Route::get('/excel_report', 'excelReport')->name('excelReport')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri');
|
||||
Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore')->middleware('permission:add-safety-and-privacy');
|
||||
Route::post('/second_step_store/{safetyAndPrivacy}', 'secondStepStore')->name('secondStepStore')->middleware('permission:add-safety-and-privacy');
|
||||
Route::post('/third_step_store/{safetyAndPrivacy}', 'thirdStepStore')->name('thirdStepStore')->middleware('permission:add-safety-and-privacy');
|
||||
|
||||
Reference in New Issue
Block a user