create new report
This commit is contained in:
@@ -7,6 +7,10 @@ enum CmmsMachineStatus: int
|
||||
case AMADE= 1;
|
||||
case RESERVE = 2;
|
||||
case DAR_MAMORIAT = 3;
|
||||
case KHAREGE_AZ_RADE = 4;
|
||||
case DAR_TAMIR = 5 ;
|
||||
case FOROKHTEH_SHODE = 6;
|
||||
case NIZE_BE_TAMIR =7 ;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
@@ -14,6 +18,10 @@ enum CmmsMachineStatus: int
|
||||
self::AMADE => 'آماده',
|
||||
self::RESERVE => 'رزرو',
|
||||
self::DAR_MAMORIAT => 'در ماموریت',
|
||||
self::KHAREGE_AZ_RADE => 'خارج از محدوده',
|
||||
self::DAR_TAMIR => 'در تعمیر',
|
||||
self::FOROKHTEH_SHODE => ' فروخته شده',
|
||||
self::NIZE_BE_TAMIR => 'نیاز به تعمیر',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Mission;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Mission;
|
||||
use App\Models\Province;
|
||||
use App\Services\Cartables\Mission\ReportService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function countryActivity(Request $request, ReportService $reportrService): JsonResponse
|
||||
{
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $reportrService->countryActivity($request),
|
||||
'provinces' => Province::all(['id', 'name_fa']),
|
||||
]);
|
||||
}
|
||||
|
||||
// public function provinceActivity(Request $request, OperatorService $operatorService): JsonResponse
|
||||
// {
|
||||
//
|
||||
// $data = $operatorService->provinceActivity(
|
||||
// $request,
|
||||
// 90,
|
||||
// );
|
||||
//
|
||||
// return $this->successResponse([
|
||||
// 'activities' => $data,
|
||||
// 'edarateShahri' => EdarateShahri::where('province_id', $request->province_id)->get(['id', 'name_fa']),
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse
|
||||
// {
|
||||
// $data = $operatorService->countryActivity(90, $request);
|
||||
// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||||
//
|
||||
// return Excel::download(new ExcelReport($data), $name);
|
||||
// }
|
||||
//
|
||||
// public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse
|
||||
// {
|
||||
// $data = $operatorService->provinceActivity(
|
||||
// $request,
|
||||
// 90,
|
||||
// );
|
||||
// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||||
//
|
||||
// return Excel::download(new AccessRoadReport($data, $request), $name);
|
||||
// }
|
||||
}
|
||||
103
app/Services/Cartables/Mission/ReportService.php
Normal file
103
app/Services/Cartables/Mission/ReportService.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\Mission;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReportService
|
||||
{
|
||||
public function dataTable(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$query = Mission::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
);
|
||||
}
|
||||
|
||||
public function countryActivity(Request $request): array
|
||||
{
|
||||
$from = null;
|
||||
$to = null;
|
||||
|
||||
$filters = json_decode($request->filters ?? '[]', true);
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (($filter['fn'] ?? null) === 'between' && ($filter['id'] ?? null) === 'created_at') {
|
||||
$from = ($filter['value'][0] ?? null) ? ($filter['value'][0] . ' 00:00:00') : null;
|
||||
$to = ($filter['value'][1] ?? null) ? ($filter['value'][1] . ' 23:59:59') : null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$from ??= '1970-01-01 00:00:00';
|
||||
$to ??= now()->endOfDay()->toDateTimeString();
|
||||
|
||||
$sql = "
|
||||
WITH r AS (
|
||||
SELECT
|
||||
p.id,
|
||||
p.name_fa AS province_name,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mv.type = 1
|
||||
AND mv.created_at BETWEEN :from AND :to
|
||||
THEN mv.id
|
||||
END) AS no_mission_count,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN m.mission_duration != m.in_area_duration
|
||||
AND m.created_at BETWEEN :from AND :to
|
||||
THEN m.id
|
||||
END) AS out_of_area_count
|
||||
|
||||
FROM provinces p
|
||||
LEFT JOIN cmms_machines cm
|
||||
ON cm.province_id = p.id
|
||||
LEFT JOIN mission_violations mv
|
||||
ON TRIM(cm.machine_code) = TRIM(mv.machine_code)
|
||||
LEFT JOIN missions m
|
||||
ON m.province_id = p.id
|
||||
|
||||
GROUP BY p.id, p.name_fa
|
||||
)
|
||||
|
||||
SELECT
|
||||
'کل کشور' AS province_name,
|
||||
SUM(no_mission_count) AS no_mission_count,
|
||||
SUM(out_of_area_count) AS out_of_area_count
|
||||
FROM r
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
province_name, no_mission_count, out_of_area_count
|
||||
FROM r
|
||||
|
||||
ORDER BY
|
||||
CASE WHEN province_name = 'کل کشور' THEN 0 ELSE 1 END,
|
||||
province_name
|
||||
";
|
||||
|
||||
return DB::select($sql, [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivity(Request $request, int $info_id): array
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -527,6 +527,15 @@ Route::prefix('missions')
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
});
|
||||
Route::prefix('report')
|
||||
->name('reports.')
|
||||
->controller(\App\Http\Controllers\V3\Dashboard\Mission\ReportController::class)
|
||||
->group(function () {
|
||||
Route::get('/country_activity', 'countryActivity')->name('countryActivity');
|
||||
Route::get('/province_activity', 'provinceActivity')->name('provinceActivity');
|
||||
Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity');
|
||||
Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('harim')
|
||||
|
||||
Reference in New Issue
Block a user