@@ -47,11 +47,17 @@ class DailyMovingMachineCommand extends Command
|
||||
$missionCodes = $missions->pluck('machine_code');
|
||||
|
||||
$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) {
|
||||
$cmm = $response->firstWhere('machineCode', '=', $code);
|
||||
|
||||
if ($violationMachineCodes->contains($cmm->machine_code)) {
|
||||
break;
|
||||
}
|
||||
|
||||
MissionViolation::query()->create([
|
||||
'machine_code' => $code,
|
||||
'machine_id' => CMMSMachine::query()->firstWhere('machine_code', '=', $code)->id,
|
||||
@@ -63,16 +69,16 @@ class DailyMovingMachineCommand extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($missionOnly as $code) {
|
||||
MissionViolation::query()->create([
|
||||
'machine_code' => $code,
|
||||
'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
||||
'type' => MissionViolationType::ADAM_TAHAROK->value,
|
||||
'request_date' => $date,
|
||||
]);
|
||||
}
|
||||
// foreach ($missionOnly as $code) {
|
||||
// MissionViolation::query()->create([
|
||||
// 'machine_code' => $code,
|
||||
// 'mission_id' => $missions->where('machine_code', '=', $code)->value('id'),
|
||||
// 'type' => MissionViolationType::ADAM_TAHAROK->value,
|
||||
// 'request_date' => $date,
|
||||
// ]);
|
||||
// }
|
||||
|
||||
$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\Traits\ApiResponse;
|
||||
use App\Models\Mission;
|
||||
use App\Models\City;
|
||||
use App\Models\Province;
|
||||
use App\Services\Cartables\Mission\ReportService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -14,45 +14,35 @@ class ReportController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function countryActivity(Request $request, ReportService $reportrService): JsonResponse
|
||||
public function countryActivity(Request $request, ReportService $reportService): JsonResponse
|
||||
{
|
||||
|
||||
return $this->successResponse([
|
||||
'activities' => $reportrService->countryActivity($request),
|
||||
'activities' => $reportService->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 provinceActivity(Request $request, ReportService $reportService): JsonResponse
|
||||
{
|
||||
return $this->successResponse([
|
||||
'activities' =>$reportService->provinceActivity($request),
|
||||
'city' => City::query()->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';
|
||||
// $data = $operatorService->countryActivity($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';
|
||||
// $data = $operatorService->provinceActivity($request);
|
||||
// $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) {
|
||||
$mission->rahdaran()->detach();
|
||||
$mission->histories()->delete();
|
||||
$mission->delete();
|
||||
});
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ class ViolationManagementController extends Controller
|
||||
'machine_code' => $machine->machine_code,//
|
||||
'station_id' => $user->station_id,
|
||||
'station_name' => RahdariPoint::query()->find( $user->station_id)->name,
|
||||
'km' => $violation->km ?? null,
|
||||
]);
|
||||
|
||||
$mission->rahdaran()->sync($request->rahdaran);
|
||||
@@ -101,6 +102,8 @@ class ViolationManagementController extends Controller
|
||||
'type'=> MissionViolationType::KHOROJ_BEDONE_MOGAVEZ->value,
|
||||
'status' => MissionViolationStatus::BEDON_EGHDAM->value,
|
||||
'request_date' => now(),
|
||||
'km' => $request->km,
|
||||
'gps' => 0,
|
||||
]);
|
||||
|
||||
return $this->successResponse();
|
||||
|
||||
@@ -26,7 +26,7 @@ class StoreRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'machine_code' => 'required',
|
||||
'km'=> 'string',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ class UpdateRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'exit_time' => 'required',
|
||||
'enter_time' => 'required',
|
||||
'exit_time' => 'date',
|
||||
'enter_time' => 'date',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class DailyMoveMachineService
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$query = MissionViolation::query();
|
||||
$query = MissionViolation::query()->with('machine:id,car_name');
|
||||
|
||||
if ($user->hasPermissionTo('manage-violation-station')) {
|
||||
$query->whereRelation('machine', 'station_id', '=', $user->station_id);
|
||||
@@ -26,7 +26,7 @@ class DailyMoveMachineService
|
||||
}
|
||||
|
||||
return DataTableFacade::run(
|
||||
MissionViolation::query(),
|
||||
$query,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
|
||||
@@ -14,8 +14,6 @@ class ReportService
|
||||
{
|
||||
$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(
|
||||
@@ -34,7 +32,7 @@ class ReportService
|
||||
$sql = "
|
||||
WITH r AS (
|
||||
SELECT
|
||||
p.id,
|
||||
p.id AS province_id,
|
||||
p.name_fa AS province_name,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
@@ -70,7 +68,7 @@ class ReportService
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
province_name, no_mission_count, out_of_area_count
|
||||
province_id, province_name, no_mission_count, out_of_area_count
|
||||
FROM r
|
||||
|
||||
ORDER BY
|
||||
@@ -85,9 +83,70 @@ class ReportService
|
||||
'to_m' => $to,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivity(Request $request, int $info_id)
|
||||
public function provinceActivity(Request $request): array
|
||||
{
|
||||
//
|
||||
$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.')
|
||||
->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_activity', 'countryActivity')->name('countryActivity')
|
||||
->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('/province_excel_activity', 'provinceExcelActivity')->name('provinceExcelActivity');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user