fix code
This commit is contained in:
@@ -4,10 +4,11 @@ namespace App\Console\Commands;
|
|||||||
|
|
||||||
use App\Enums\ActivityMachineType;
|
use App\Enums\ActivityMachineType;
|
||||||
use App\Models\Mission;
|
use App\Models\Mission;
|
||||||
use App\Models\AssignmentFails;
|
use App\Models\MissionViolation;
|
||||||
use App\Services\CMMS\DailyMovingMachinesService;
|
use App\Services\CMMS\DailyMovingMachinesService;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class DailyMovingMachineCommand extends Command
|
class DailyMovingMachineCommand extends Command
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,7 @@ class DailyMovingMachineCommand extends Command
|
|||||||
$vehiclesInfo = $dailyMovingMachines->run();
|
$vehiclesInfo = $dailyMovingMachines->run();
|
||||||
$response = collect($vehiclesInfo['vehiclesInfo']);
|
$response = collect($vehiclesInfo['vehiclesInfo']);
|
||||||
|
|
||||||
$date = now()->toDateString();
|
$date = Carbon::yesterday()->toDateString();
|
||||||
|
|
||||||
$cmms = $response->pluck('machineCode');
|
$cmms = $response->pluck('machineCode');
|
||||||
|
|
||||||
@@ -46,27 +47,27 @@ class DailyMovingMachineCommand extends Command
|
|||||||
$missionOnly = $mission->diff($cmms);
|
$missionOnly = $mission->diff($cmms);
|
||||||
|
|
||||||
foreach ($cmmsOnly as $code) {
|
foreach ($cmmsOnly as $code) {
|
||||||
$cmm = $response->firstWhere('machineCode', $code);
|
$cmm = $response->firstWhere('machineCode', '=', $code);
|
||||||
|
|
||||||
AssignmentFails::query()->create([
|
MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
'machine_code' => $code,
|
||||||
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(),
|
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value,
|
||||||
'request_date' => $date,
|
'request_date' => $date,
|
||||||
'mileage' => $cmm['mileageKM'],
|
'mileage' => $cmm['mileageKM'],
|
||||||
'exit_time' => $cmm['exit_time'],
|
// 'exit_time' => $cmm['exit_time'],
|
||||||
'enter_time' => $cmm['enter_time'],
|
// 'enter_time' => $cmm['enter_time'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($missionOnly as $code) {
|
foreach ($missionOnly as $code) {
|
||||||
$missionId = Mission::query()->where('machine_code', $code)
|
$missionId = Mission::query()->where('machine_code', $code)
|
||||||
->whereDate('start_time', today())
|
->whereDate('start_time', $date)
|
||||||
->value('id');
|
->value('id');
|
||||||
|
|
||||||
AssignmentFails::query()->create([
|
MissionViolation::query()->create([
|
||||||
'machine_code' => $code,
|
'machine_code' => $code,
|
||||||
'mission_id' => $missionId,
|
'mission_id' => $missionId,
|
||||||
'type' => ActivityMachineType::ADAM_TAHAROK->label(),
|
'type' => ActivityMachineType::ADAM_TAHAROK->value,
|
||||||
'request_date' => $date,
|
'request_date' => $date,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class Kernel extends ConsoleKernel
|
|||||||
->appendOutputTo(storage_path('logs/telescope.log'));
|
->appendOutputTo(storage_path('logs/telescope.log'));
|
||||||
|
|
||||||
$schedule->command('daily_moving_machine')
|
$schedule->command('daily_moving_machine')
|
||||||
->dailyAt('23:59')->appendOutputTo(storage_path('logs/dailymovingmachine.log'));
|
->dailyAt('02:00')->appendOutputTo(storage_path('logs/dailymovingmachine.log'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,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\Mission;
|
||||||
use App\Services\Cartables\Mission\DailyMoveMachineService;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class DetailController extends Controller
|
class DetailController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,7 +13,7 @@ class DetailController extends Controller
|
|||||||
|
|
||||||
public function machines(Mission $mission): JsonResponse
|
public function machines(Mission $mission): JsonResponse
|
||||||
{
|
{
|
||||||
return $this->successResponse($mission->machine()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number']));
|
return $this->successResponse($mission->machines()->get(['cmms_machines.id', 'cmms_machines.machine_code', 'cmms_machines.car_name', 'cmms_machines.plak_number']));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rahdaran(Mission $mission): JsonResponse
|
public function rahdaran(Mission $mission): JsonResponse
|
||||||
@@ -33,11 +31,4 @@ class DetailController extends Controller
|
|||||||
|
|
||||||
return $this->successResponse($rahdaran);
|
return $this->successResponse($rahdaran);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse
|
|
||||||
{
|
|
||||||
$data = $dailyMoveMachineService->dataTable($request);
|
|
||||||
|
|
||||||
return response()->json($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\V3\Dashboard\Mission;
|
||||||
|
|
||||||
|
use App\Enums\MissionCategory;
|
||||||
|
use App\Enums\MissionStates;
|
||||||
|
use App\Enums\MissionTypes;
|
||||||
|
use App\Enums\MissionZones;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Controllers\V3\Dashboard\RoadPatrol\OperatorController;
|
||||||
|
use App\Http\Requests\V3\Mission\RequestPortal\NoProcessRequest;
|
||||||
|
use App\Http\Traits\ApiResponse;
|
||||||
|
use App\Models\Mission;
|
||||||
|
use App\Services\Cartables\Mission\DailyMoveMachineService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ViolationManagementController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function index(Request $request, DailyMoveMachineService $dailyMoveMachineService): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $dailyMoveMachineService->dataTable($request);
|
||||||
|
|
||||||
|
return response()->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function noProcess(NoProcessRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($request) {
|
||||||
|
|
||||||
|
$start = Carbon::parse($request->start_date);
|
||||||
|
$end = Carbon::parse($request->end_date);
|
||||||
|
$type = $start->diffInMinutes($end) > 480 ? MissionTypes::NO_PROCESS_ROZANE->value : MissionTypes::NO_PROCESS_SAATY->value;
|
||||||
|
$user = auth()->user();
|
||||||
|
$zone = $request->zone;
|
||||||
|
$state = MissionStates::END_MISSION->value;
|
||||||
|
|
||||||
|
$mission = Mission::query()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'username' => $user->username,
|
||||||
|
'province_id' => $user->province_id,
|
||||||
|
'province_name' => $user->province_fa,
|
||||||
|
'edare_shahri_id' => $user->edarate_shahri_id ?? null,
|
||||||
|
'edare_shahri_name' => $user->edarate_shahri_name ?? null,
|
||||||
|
'zone' => $zone,
|
||||||
|
'zone_fa' => MissionZones::name($zone),
|
||||||
|
'type' => $type,
|
||||||
|
'type_fa' => MissionTypes::name($type),
|
||||||
|
'start_date' => $request->start_date,
|
||||||
|
'end_date' => $request->end_date,
|
||||||
|
'end_point' => $request->end_point,
|
||||||
|
'area' => json_encode($request->area),
|
||||||
|
'category_id' => $request->category_id,
|
||||||
|
'category_name' => MissionCategory::name($request->category_id),
|
||||||
|
'start_time' => $request->start_date,
|
||||||
|
'finish_time' => $request->end_date,
|
||||||
|
'state_id' => $state,
|
||||||
|
'state_name' => MissionStates::name($state),
|
||||||
|
'explanation' => $request->explanation,
|
||||||
|
'request_date' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$mission->rahdaran()->sync($request->rahdaran);
|
||||||
|
$mission->machines()->attach($request->machines);
|
||||||
|
$mission->rahdaran()->attach($request->driver, ['is_driver' => true]);
|
||||||
|
|
||||||
|
if ($mission->category_id == 2) {
|
||||||
|
$rpc = new OperatorController;
|
||||||
|
$rpc->store($mission);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ namespace App\Models;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class AssignmentFails extends Model
|
class MissionViolation extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
protected $guarded =[];
|
protected $guarded =[];
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Services\CMMS;
|
namespace App\Services\CMMS;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -54,10 +54,12 @@ class DailyMovingMachinesService
|
|||||||
|
|
||||||
private function makeInputParameters(): string
|
private function makeInputParameters(): string
|
||||||
{
|
{
|
||||||
|
$day = Carbon::yesterday()->toDateString();
|
||||||
|
|
||||||
return json_encode([
|
return json_encode([
|
||||||
"username" => $this->username,
|
"username" => $this->username,
|
||||||
"password" => $this->password,
|
"password" => $this->password,
|
||||||
"day" => today(),
|
"day" => $day,
|
||||||
"minMileage" => 10,
|
"minMileage" => 10,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Services\Cartables\Mission;
|
namespace App\Services\Cartables\Mission;
|
||||||
|
|
||||||
use App\Facades\DataTable\DataTableFacade;
|
use App\Facades\DataTable\DataTableFacade;
|
||||||
use App\Models\AssignmentFails;
|
use App\Models\MissionViolation;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class DailyMoveMachineService
|
class DailyMoveMachineService
|
||||||
@@ -11,7 +11,7 @@ class DailyMoveMachineService
|
|||||||
public function dataTable(Request $request)
|
public function dataTable(Request $request)
|
||||||
{
|
{
|
||||||
return DataTableFacade::run(
|
return DataTableFacade::run(
|
||||||
AssignmentFails::query(),
|
MissionViolation::query(),
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\AssignmentFails;
|
use App\Models\MissionViolation;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
class AssignmentFailsFactory extends Factory
|
class AssignmentFailsFactory extends Factory
|
||||||
{
|
{
|
||||||
protected $model = AssignmentFails::class;
|
protected $model = MissionViolation::class;
|
||||||
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::create('assignment_fails', function (Blueprint $table) {
|
Schema::create('mission_violations', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('mission_id')->constrained('missions')->nullable();
|
$table->foreignId('mission_id')->nullable()->constrained('missions');
|
||||||
$table->string('machine_code')->nullable();
|
$table->string('machine_code')->nullable();
|
||||||
$table->date('request_date')->nullable();
|
$table->date('request_date')->nullable();
|
||||||
$table->string('type')->nullable();
|
$table->tinyInteger('type')->nullable();
|
||||||
$table->bigInteger('mileage')->nullable();
|
$table->bigInteger('mileage')->nullable();
|
||||||
$table->dateTime('exit_time')->nullable();
|
$table->dateTime('exit_time')->nullable();
|
||||||
$table->dateTime('enter_time')->nullable();
|
$table->dateTime('enter_time')->nullable();
|
||||||
@@ -30,6 +30,6 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('assignment_fails');
|
Schema::dropIfExists('mission_violations');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user