diff --git a/app/Console/Commands/ExtractGeometryForCities.php b/app/Console/Commands/ExtractGeometryForCities.php index 42108fee..9706f477 100644 --- a/app/Console/Commands/ExtractGeometryForCities.php +++ b/app/Console/Commands/ExtractGeometryForCities.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use App\Models\City; use Illuminate\Console\Command; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Log; @@ -27,8 +28,9 @@ class ExtractGeometryForCities extends Command /** * Execute the console command. + * @throws FileNotFoundException */ - public function handle() + public function handle(): int { $jsonPath = $this->argument('jsonPath'); @@ -103,8 +105,6 @@ class ExtractGeometryForCities extends Command continue; } - - $query = City::query() ->find($cityId); @@ -122,8 +122,6 @@ class ExtractGeometryForCities extends Command { $this->error("Something went wrong: $th"); } - - } return parent::SUCCESS; diff --git a/app/Exports/V3/AccidentReceipt/CountryReport.php b/app/Exports/V3/AccidentReceipt/CountryReport.php index e05bdb64..caa93bb4 100644 --- a/app/Exports/V3/AccidentReceipt/CountryReport.php +++ b/app/Exports/V3/AccidentReceipt/CountryReport.php @@ -26,7 +26,8 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing $country = array_search(-1, array_column($data['data'], 'province_id')); $activities[] = [ - 'name' => 'کل کشور', + 'province_id' => -1, + 'province_fa' => 'کل کشور', 'tedade' => $data['data'][$country]->tedade, 'police_rah' => $data['data'][$country]->police_rah, 'gozaresh_gasht' => $data['data'][$country]->gozaresh_gasht, @@ -35,6 +36,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing 'vasel_shode_bimeh' => $data['data'][$country]->vasel_shode_bimeh ?? 0, 'vasel_shode_daghi' => $data['data'][$country]->vasel_shode_daghi ?? 0, 'vasel_shode_final' => $data['data'][$country]->vasel_shode_final ?? 0, + 'egdam' => $data['data'][$country]->egdam ?? 0, + 'khatm' => $data['data'][$country]->khatm ?? 0, + 'pardakht' => $data['data'][$country]->pardakht ?? 0, ]; foreach (Province::all() as $province) { @@ -43,7 +47,8 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing if ($existingProvince) { $activities[] = [ - 'name' => $province->name_fa, + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, 'tedade' => $data['data'][$existingProvince]->tedade, 'police_rah' => $data['data'][$existingProvince]->police_rah, 'gozaresh_gasht' => $data['data'][$existingProvince]->gozaresh_gasht, @@ -52,10 +57,14 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing 'vasel_shode_bimeh' => $data['data'][$existingProvince]->vasel_shode_bimeh ?? 0, 'vasel_shode_daghi' => $data['data'][$existingProvince]->vasel_shode_daghi ?? 0, 'vasel_shode_final' => $data['data'][$existingProvince]->vasel_shode_final ?? 0, + 'egdam' => $data['data'][$country]->egdam ?? 0, + 'khatm' => $data['data'][$country]->khatm ?? 0, + 'pardakht' => $data['data'][$country]->pardakht ?? 0, ]; } else { $activities[] = [ - 'name' => $province->name_fa, + 'province_id' => $province->id, + 'province_fa' => $province->name_fa, 'tedade' => "", 'police_rah' => "", 'gozaresh_gasht' => "", @@ -64,6 +73,9 @@ class CountryReport implements FromView, ShouldAutoSize, WithEvents, WithDrawing 'vasel_shode_bimeh' => "", 'vasel_shode_daghi' => "", 'vasel_shode_final' => "", + 'egdam' => "", + 'khatm' => "", + 'pardakht' => "", ]; } } diff --git a/app/Exports/V3/AccidentReceipt/ProvinceReport.php b/app/Exports/V3/AccidentReceipt/ProvinceReport.php index ab63e7f6..7d9f7cd2 100644 --- a/app/Exports/V3/AccidentReceipt/ProvinceReport.php +++ b/app/Exports/V3/AccidentReceipt/ProvinceReport.php @@ -26,7 +26,8 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin $province = array_search(-1, array_column($reportData, 'province_id')); $activities[] = [ - 'name' => 'کل استان', + 'city_id' => -1, + 'city_fa' => 'کل استان', 'tedade' => $reportData['data'][$province]->tedade, 'police_rah' => $reportData['data'][$province]->police_rah, 'gozaresh_gasht' => $reportData['data'][$province]->gozaresh_gasht, @@ -35,6 +36,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin 'vasel_shode_bimeh' => $reportData['data'][$province]->vasel_shode_bimeh ?? 0, 'vasel_shode_daghi' => $reportData['data'][$province]->vasel_shode_daghi ?? 0, 'vasel_shode_final' => $reportData['data'][$province]->vasel_shode_final ?? 0, + 'egdam' => $reportData['data'][$province]->egdam ?? 0, + 'khatm' => $reportData['data'][$province]->khatm ?? 0, + 'pardakht' => $reportData['data'][$province]->pardakht ?? 0, ]; foreach ($inputData['cities'] as $city) { @@ -43,7 +47,8 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin if ($existingCity) { $activities[] = [ - 'name' => $city->name_fa, + 'city_id' => -1, + 'city_fa' => 'کل استان', 'tedade' => $reportData['data'][$existingCity]->tedade, 'police_rah' => $reportData['data'][$existingCity]->police_rah, 'gozaresh_gasht' => $reportData['data'][$existingCity]->gozaresh_gasht, @@ -52,6 +57,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin 'vasel_shode_bimeh' => $reportData['data'][$existingCity]->vasel_shode_bimeh ?? 0, 'vasel_shode_daghi' => $reportData['data'][$existingCity]->vasel_shode_daghi ?? 0, 'vasel_shode_final' => $reportData['data'][$existingCity]->vasel_shode_final ?? 0, + 'egdam' => $reportData['data'][$province]->egdam ?? 0, + 'khatm' => $reportData['data'][$province]->khatm ?? 0, + 'pardakht' => $reportData['data'][$province]->pardakht ?? 0, ]; } else { $activities[] = [ @@ -64,6 +72,9 @@ class ProvinceReport implements FromView, ShouldAutoSize, WithEvents, WithDrawin 'vasel_shode_bimeh' => "", 'vasel_shode_daghi' => "", 'vasel_shode_final' => "", + 'egdam' => "", + 'khatm' => "", + 'pardakht' => "", ]; } } diff --git a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptReportController.php b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptReportController.php index 6669bfed..1d4d8920 100644 --- a/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptReportController.php +++ b/app/Http/Controllers/V3/Dashboard/Accident/AccidentReceiptReportController.php @@ -12,6 +12,7 @@ use App\Services\Cartables\AccidentReceiptTableService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; +use PhpOffice\PhpSpreadsheet\Exception; use Symfony\Component\HttpFoundation\BinaryFileResponse; class AccidentReceiptReportController extends Controller @@ -38,6 +39,10 @@ class AccidentReceiptReportController extends Controller ]); } + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ public function countryExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse { $data = $accidentReceiptTableService->countryReport($request); @@ -45,6 +50,10 @@ class AccidentReceiptReportController extends Controller return Excel::download(new CountryReport($data), $name); } + /** + * @throws Exception + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception + */ public function provinceExcelReport(Request $request, AccidentReceiptTableService $accidentReceiptTableService): BinaryFileResponse { $data = $accidentReceiptTableService->provinceReport($request); diff --git a/composer.json b/composer.json index a2345809..52962f74 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "laravel/ui": "^4.4", "maatwebsite/excel": "^3.1", "morilog/jalali": "3.*", - "spatie/laravel-permission": "^5.10" + "spatie/laravel-permission": "^5.10", + "usmanhalalit/laracsv": "^2.1" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.9", diff --git a/composer.lock b/composer.lock index 2928ac05..21a177df 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "379d6ba4ded00ca7079f26aa5b12e04e", + "content-hash": "67bcaf1ce932d76ea3acb0bd4e2abf10", "packages": [ { "name": "beberlei/assert", @@ -2685,6 +2685,97 @@ ], "time": "2022-12-11T20:36:23+00:00" }, + { + "name": "league/csv", + "version": "9.24.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "e0221a3f16aa2a823047d59fab5809d552e29bc8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/e0221a3f16aa2a823047d59fab5809d552e29bc8", + "reference": "e0221a3f16aa2a823047d59fab5809d552e29bc8", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1.2" + }, + "require-dev": { + "ext-dom": "*", + "ext-xdebug": "*", + "friendsofphp/php-cs-fixer": "^3.75.0", + "phpbench/phpbench": "^1.4.1", + "phpstan/phpstan": "^1.12.27", + "phpstan/phpstan-deprecation-rules": "^1.2.1", + "phpstan/phpstan-phpunit": "^1.4.2", + "phpstan/phpstan-strict-rules": "^1.6.2", + "phpunit/phpunit": "^10.5.16 || ^11.5.22", + "symfony/var-dumper": "^6.4.8 || ^7.3.0" + }, + "suggest": { + "ext-dom": "Required to use the XMLConverter and the HTMLConverter classes", + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters", + "ext-mbstring": "Needed to ease transcoding CSV using mb stream filters", + "ext-mysqli": "Requiered to use the package with the MySQLi extension", + "ext-pdo": "Required to use the package with the PDO extension", + "ext-pgsql": "Requiered to use the package with the PgSQL extension", + "ext-sqlite3": "Required to use the package with the SQLite3 extension" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "League\\Csv\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "CSV data manipulation made easy in PHP", + "homepage": "https://csv.thephpleague.com", + "keywords": [ + "convert", + "csv", + "export", + "filter", + "import", + "read", + "transform", + "write" + ], + "support": { + "docs": "https://csv.thephpleague.com", + "issues": "https://github.com/thephpleague/csv/issues", + "rss": "https://github.com/thephpleague/csv/releases.atom", + "source": "https://github.com/thephpleague/csv" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2025-06-25T14:53:51+00:00" + }, { "name": "league/flysystem", "version": "3.23.1", @@ -7138,6 +7229,66 @@ }, "time": "2023-12-08T13:03:43+00:00" }, + { + "name": "usmanhalalit/laracsv", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/usmanhalalit/laracsv.git", + "reference": "98016abe4c55e7ed3c97a3e0b930cbac58374f57" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/usmanhalalit/laracsv/zipball/98016abe4c55e7ed3c97a3e0b930cbac58374f57", + "reference": "98016abe4c55e7ed3c97a3e0b930cbac58374f57", + "shasum": "" + }, + "require": { + "illuminate/database": ">=5.2", + "league/csv": "^9.0", + "php": ">=7.1" + }, + "require-dev": { + "fzaninotto/faker": "^1.8", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Laracsv\\": "src/Laracsv/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Muhammad Usman", + "email": "hi@usman.it", + "role": "Developer" + } + ], + "description": "A Laravel package to easily generate CSV files from Eloquent model.", + "homepage": "https://github.com/usmanhalalit/laracsv", + "keywords": [ + "csv", + "eloquent", + "export", + "laravel" + ], + "support": { + "issues": "https://github.com/usmanhalalit/laracsv/issues", + "source": "https://github.com/usmanhalalit/laracsv/tree/master" + }, + "funding": [ + { + "url": "https://github.com/usmanhalalit", + "type": "github" + } + ], + "time": "2020-06-19T09:31:32+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.0", diff --git a/routes/v3.php b/routes/v3.php index 1dcb42c3..0d22bded 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -595,3 +595,8 @@ Route::prefix('user_management') Route::post('/change_password/{user}', 'changePassword')->name('changePassword'); Route::post('delete-role/{id}', 'deleteRole')->name('deleteRole'); }); + +Route::get('/test', function () { + $csvExporter = new \Laracsv\Export(); + $csvExporter->build(\App\Models\User::all(), ['id' => 'کد یکتا', 'username' => 'نام کاربری'])->download(); +}); \ No newline at end of file