@@ -47,11 +47,17 @@ class DailyMovingMachineCommand extends Command
|
|||||||
$missionCodes = $missions->pluck('machine_code');
|
$missionCodes = $missions->pluck('machine_code');
|
||||||
|
|
||||||
$cmmsOnly = $cmms->diff($missionCodes);
|
$cmmsOnly = $cmms->diff($missionCodes);
|
||||||
$missionOnly = $missionCodes->diff($cmms);
|
// $missionOnly = $missionCodes->diff($cmms);
|
||||||
|
|
||||||
|
$violationMachineCodes = MissionViolation::query()->whereDate('request_date', $date)->pluck('machine_code');
|
||||||
|
|
||||||
foreach ($cmmsOnly as $code) {
|
foreach ($cmmsOnly as $code) {
|
||||||
$cmm = $response->firstWhere('machineCode', '=', $code);
|
$cmm = $response->firstWhere('machineCode', '=', $code);
|
||||||
|
|
||||||
|
if ($violationMachineCodes->contains($cmm->machine_code)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
MissionViolation::query()->create([
|
MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
'machine_code' => $code,
|
||||||
'machine_id' => CMMSMachine::query()->firstWhere('machine_code', '=', $code)->id,
|
'machine_id' => CMMSMachine::query()->firstWhere('machine_code', '=', $code)->id,
|
||||||
@@ -63,16 +69,16 @@ class DailyMovingMachineCommand extends Command
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($missionOnly as $code) {
|
// foreach ($missionOnly as $code) {
|
||||||
MissionViolation::query()->create([
|
// MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
// 'machine_code' => $code,
|
||||||
'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
// 'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
||||||
'type' => MissionViolationType::ADAM_TAHAROK->value,
|
// 'type' => MissionViolationType::ADAM_TAHAROK->value,
|
||||||
'request_date' => $date,
|
// 'request_date' => $date,
|
||||||
]);
|
// ]);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
||||||
$this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
// $this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace App\Http\Controllers\V3\Dashboard\Mission;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\Mission;
|
use App\Models\City;
|
||||||
use App\Models\Province;
|
use App\Models\Province;
|
||||||
use App\Services\Cartables\Mission\ReportService;
|
use App\Services\Cartables\Mission\ReportService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@@ -14,45 +14,35 @@ class ReportController extends Controller
|
|||||||
{
|
{
|
||||||
use ApiResponse;
|
use ApiResponse;
|
||||||
|
|
||||||
public function countryActivity(Request $request, ReportService $reportrService): JsonResponse
|
public function countryActivity(Request $request, ReportService $reportService): JsonResponse
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->successResponse([
|
return $this->successResponse([
|
||||||
'activities' => $reportrService->countryActivity($request),
|
'activities' => $reportService->countryActivity($request),
|
||||||
'provinces' => Province::all(['id', 'name_fa']),
|
'provinces' => Province::all(['id', 'name_fa']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function provinceActivity(Request $request, OperatorService $operatorService): JsonResponse
|
public function provinceActivity(Request $request, ReportService $reportService): JsonResponse
|
||||||
// {
|
{
|
||||||
//
|
return $this->successResponse([
|
||||||
// $data = $operatorService->provinceActivity(
|
'activities' =>$reportService->provinceActivity($request),
|
||||||
// $request,
|
'city' => City::query()->where('province_id', $request->province_id)->get(['id', 'name_fa']),
|
||||||
// 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
|
// public function countryExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse
|
||||||
// {
|
// {
|
||||||
// $data = $operatorService->countryActivity(90, $request);
|
// $data = $operatorService->countryActivity($request);
|
||||||
// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
// $name = 'گزارش تخلفات ماموریت ها '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||||||
//
|
//
|
||||||
// return Excel::download(new ExcelReport($data), $name);
|
// return Excel::download(new ExcelReport($data), $name);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse
|
// public function provinceExcelActivity(Request $request, OperatorService $operatorService): BinaryFileResponse
|
||||||
// {
|
// {
|
||||||
// $data = $operatorService->provinceActivity(
|
// $data = $operatorService->provinceActivity($request);
|
||||||
// $request,
|
// $name = 'گزارش تخلفات ماموریت ها '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
||||||
// 90,
|
|
||||||
// );
|
|
||||||
// $name = 'گزارش نگهداری حریم راه برای راه دسترسی غیر مجاز '.verta()->now()->format('Y-m-d H-i').'.xlsx';
|
|
||||||
//
|
//
|
||||||
// return Excel::download(new AccessRoadReport($data, $request), $name);
|
// return Excel::download(new ProvinceExcelReport($data, $request), $name);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ class RequestPortalController extends Controller
|
|||||||
{
|
{
|
||||||
DB::transaction(function () use ($mission) {
|
DB::transaction(function () use ($mission) {
|
||||||
$mission->rahdaran()->detach();
|
$mission->rahdaran()->detach();
|
||||||
|
$mission->histories()->delete();
|
||||||
$mission->delete();
|
$mission->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class ViolationManagementController extends Controller
|
|||||||
'machine_code' => $machine->machine_code,//
|
'machine_code' => $machine->machine_code,//
|
||||||
'station_id' => $user->station_id,
|
'station_id' => $user->station_id,
|
||||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
||||||
|
'km' => $violation->km ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$mission->rahdaran()->sync($request->rahdaran);
|
$mission->rahdaran()->sync($request->rahdaran);
|
||||||
@@ -101,6 +102,8 @@ class ViolationManagementController extends Controller
|
|||||||
'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
||||||
'status' => MissionViolationStatus::BEDON_EGHDAM->value,
|
'status' => MissionViolationStatus::BEDON_EGHDAM->value,
|
||||||
'request_date' => now(),
|
'request_date' => now(),
|
||||||
|
'km' => $request->km,
|
||||||
|
'gps' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class StoreRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'machine_code' => 'required',
|
'machine_code' => 'required',
|
||||||
|
'km'=> 'string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ class UpdateRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'exit_time' => 'required',
|
'exit_time' => 'date',
|
||||||
'enter_time' => 'required',
|
'enter_time' => 'date',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class DailyMoveMachineService
|
|||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
$query = MissionViolation::query();
|
$query = MissionViolation::query()->with('machine:id,car_name');
|
||||||
|
|
||||||
if ($user->hasPermissionTo('manage-violation-station')) {
|
if ($user->hasPermissionTo('manage-violation-station')) {
|
||||||
$query->whereRelation('machine', 'station_id', '=', $user->station_id);
|
$query->whereRelation('machine', 'station_id', '=', $user->station_id);
|
||||||
@@ -26,7 +26,7 @@ class DailyMoveMachineService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return DataTableFacade::run(
|
return DataTableFacade::run(
|
||||||
MissionViolation::query(),
|
$query,
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ class ReportService
|
|||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
|
||||||
|
|
||||||
$query = Mission::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
$query = Mission::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||||
|
|
||||||
return DataTableFacade::run(
|
return DataTableFacade::run(
|
||||||
@@ -34,7 +32,7 @@ class ReportService
|
|||||||
$sql = "
|
$sql = "
|
||||||
WITH r AS (
|
WITH r AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.id,
|
p.id AS province_id,
|
||||||
p.name_fa AS province_name,
|
p.name_fa AS province_name,
|
||||||
|
|
||||||
COUNT(DISTINCT CASE
|
COUNT(DISTINCT CASE
|
||||||
@@ -70,7 +68,7 @@ class ReportService
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
province_name, no_mission_count, out_of_area_count
|
province_id, province_name, no_mission_count, out_of_area_count
|
||||||
FROM r
|
FROM r
|
||||||
|
|
||||||
ORDER BY
|
ORDER BY
|
||||||
@@ -85,9 +83,70 @@ class ReportService
|
|||||||
'to_m' => $to,
|
'to_m' => $to,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
public function provinceActivity(Request $request): array
|
||||||
public function provinceActivity(Request $request, int $info_id)
|
|
||||||
{
|
{
|
||||||
//
|
$provinceId = $request->province_id ?? auth()->user()->province_id;
|
||||||
|
$from = $request->from_date ?? today()->startOfDay();
|
||||||
|
$to = $request->to_date ?? today()->endOfDay();
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
WITH r AS (
|
||||||
|
SELECT
|
||||||
|
c.id AS city_id,
|
||||||
|
c.name_fa AS city_name,
|
||||||
|
|
||||||
|
COUNT(DISTINCT CASE
|
||||||
|
WHEN mv.type = 1
|
||||||
|
AND mv.created_at BETWEEN :from_mv AND :to_mv
|
||||||
|
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_m AND :to_m
|
||||||
|
THEN m.id
|
||||||
|
END) AS out_of_area_count
|
||||||
|
|
||||||
|
FROM cities c
|
||||||
|
|
||||||
|
LEFT JOIN cmms_machines cm
|
||||||
|
ON cm.city_id = c.id
|
||||||
|
|
||||||
|
LEFT JOIN mission_violations mv
|
||||||
|
ON TRIM(cm.machine_code) = TRIM(mv.machine_code)
|
||||||
|
|
||||||
|
LEFT JOIN missions m
|
||||||
|
ON m.city_id = c.id
|
||||||
|
|
||||||
|
WHERE c.province_id = :province_id
|
||||||
|
|
||||||
|
GROUP BY c.id, c.name_fa
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
-1 AS city_id,
|
||||||
|
'کل استان' AS city_name,
|
||||||
|
SUM(no_mission_count) AS no_mission_count,
|
||||||
|
SUM(out_of_area_count) AS out_of_area_count
|
||||||
|
FROM r
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
city_id, city_name, no_mission_count, out_of_area_count
|
||||||
|
FROM r
|
||||||
|
|
||||||
|
ORDER BY
|
||||||
|
CASE WHEN city_id = -1 THEN 0 ELSE 1 END,
|
||||||
|
city_name
|
||||||
|
";
|
||||||
|
|
||||||
|
return DB::select($sql, [
|
||||||
|
'province_id' => $provinceId,
|
||||||
|
'from_mv' => $from,
|
||||||
|
'to_mv' => $to,
|
||||||
|
'from_m' => $from,
|
||||||
|
'to_m' => $to,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?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('mission_violations', function (Blueprint $table) {
|
||||||
|
$table->string('km')->nullable();
|
||||||
|
$table->unsignedTinyInteger('gps')->default(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('mission_violations', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['km', 'gps']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -537,8 +537,10 @@ Route::prefix('missions')
|
|||||||
->name('reports.')
|
->name('reports.')
|
||||||
->controller(\App\Http\Controllers\V3\Dashboard\Mission\ReportController::class)
|
->controller(\App\Http\Controllers\V3\Dashboard\Mission\ReportController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/country_activity', 'countryActivity')->name('countryActivity');
|
Route::get('/country_activity', 'countryActivity')->name('countryActivity')
|
||||||
Route::get('/province_activity', 'provinceActivity')->name('provinceActivity');
|
->middleware('permission:mission-report-country');
|
||||||
|
Route::get('/province_activity', 'provinceActivity')->name('provinceActivity')
|
||||||
|
->middleware('permission:mission-report-province');
|
||||||
Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity');
|
Route::get('/country_excel_activity', 'countryExcelActivity')->name('countryExcelActivity');
|
||||||
Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
|
Route::get('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user