115 lines
3.6 KiB
PHP
115 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Maintenance\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Modules\Maintenance\Models\HistoryEntry;
|
|
use App\Modules\Maintenance\Services\MaintenanceReportService;
|
|
use App\Modules\Maintenance\Traits\ResolvesBusiness;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MaintenanceReportController extends Controller
|
|
{
|
|
use ResolvesBusiness;
|
|
|
|
public function __construct(
|
|
protected MaintenanceReportService $reportService
|
|
) {}
|
|
|
|
public function equipmentCost(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess(
|
|
$this->reportService->equipmentCostReport($business, $request->integer('equipment_id') ?: null)
|
|
);
|
|
}
|
|
|
|
public function downtime(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess(
|
|
$this->reportService->downtimeReport($business, $request->get('from'), $request->get('to'))
|
|
);
|
|
}
|
|
|
|
public function technicianPerformance(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess($this->reportService->technicianPerformance($business));
|
|
}
|
|
|
|
public function sparePartsConsumption(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess(
|
|
$this->reportService->sparePartsConsumption($business, $request->get('from'), $request->get('to'))
|
|
);
|
|
}
|
|
|
|
public function monthly(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess(
|
|
$this->reportService->monthlyStatistics(
|
|
$business,
|
|
(int) $request->get('year', now()->year),
|
|
(int) $request->get('month', now()->month)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function failureAnalysis(Request $request)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
return $this->jsonSuccess($this->reportService->failureAnalysis($business));
|
|
}
|
|
|
|
public function history(Request $request, int $equipmentId)
|
|
{
|
|
$business = $this->resolveBusiness($request);
|
|
if (! $business) {
|
|
return $this->jsonError('کسبوکار یافت نشد.', 404);
|
|
}
|
|
|
|
$entries = HistoryEntry::where('business_id', $business->id)
|
|
->where('equipment_id', $equipmentId)
|
|
->with('performer:id,name')
|
|
->orderByDesc('performed_at')
|
|
->paginate((int) $request->get('per_page', 20));
|
|
|
|
return $this->jsonSuccess([
|
|
'items' => $entries->items(),
|
|
'pagination' => [
|
|
'total' => $entries->total(),
|
|
'per_page' => $entries->perPage(),
|
|
'current_page' => $entries->currentPage(),
|
|
'last_page' => $entries->lastPage(),
|
|
],
|
|
]);
|
|
}
|
|
}
|