Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /home/elvh3918/public_html/pmm/app/Http/Controllers/API/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/elvh3918/public_html/pmm/app/Http/Controllers/API/GlobalAPIReportController.php
<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Trans\Maintenance;
use App\Models\Master\Customer;
use App\Models\Master\Technician;
use App\Models\Master\Item;

class GlobalAPIReportController extends Controller
{
    public function report_maintenance($from_date, $to_date, $tenant_id, $item_code) {
        $query = Maintenance::with('tenant', 'technician', 'customer', 'item', 'user', 'maintenance_detail.part')->whereBetween('date_trans', [$from_date, $to_date]);
        if ($tenant_id > 0) {
            $query = $query->whereRelation('tenant', 'id', '=', $tenant_id);
        }
        if ($item_code != 'null') {
            $query = $query->whereRelation('item', 'code', '=', $item_code);
        }

        $query = $query->orderBy('date_trans', 'asc')->get();
        return response()->json($query);
    }

    public function report_maintenance_by_customer($from_date, $to_date, $customer_id, $item_id, $item_code) {
        $query = Maintenance::with('tenant', 'technician', 'customer', 'item', 'user', 'maintenance_detail.part')->whereBetween('date_trans', [$from_date, $to_date]);
        if ($item_id > 0) {
            $query = $query->whereRelation('item', 'id', '=', $item_id);
        }
        
        if ($customer_id > 0) {
            $query = $query->whereRelation('customer', 'id', '=', $customer_id);
        }

        if ($item_code != 'null') {
            $query = $query->whereRelation('item', 'code', '=', $item_code);
        }

        $query = $query->orderBy('date_trans', 'asc')->get();
        return response()->json($query);
    }

    public function report_customer($from_date, $to_date, $tenant_id) {
        $query = Customer::with('maintenance', 'maintenance.tenant', 'maintenance.technician', 'maintenance.customer', 'maintenance.item', 'maintenance.user', 'maintenance.maintenance_detail.part')->whereRelation('maintenance', 'date_trans', '>=', $from_date)->whereRelation('maintenance', 'date_trans', '<=', $to_date);
        if ($tenant_id > 0) {
            $query = $query->whereRelation('maintenance', 'tenant_id', '=', $tenant_id);
        }

        $query = $query->withCount('maintenance')->get();
        return response()->json($query);
    }

    public function report_technician($from_date, $to_date, $tenant_id) {
        $query = Technician::with('maintenance', 'maintenance.tenant', 'maintenance.technician', 'maintenance.customer', 'maintenance.item', 'maintenance.user', 'maintenance.maintenance_detail.part')->whereRelation('maintenance', 'date_trans', '>=', $from_date)->whereRelation('maintenance', 'date_trans', '<=', $to_date);
        if ($tenant_id > 0) {
            $query = $query->whereRelation('maintenance', 'tenant_id', '=', $tenant_id);
        }

        $query = $query->withCount('maintenance')->get();
        return response()->json($query);
    }

    public function report_item($from_date, $to_date, $tenant_id, $customer_id) {
        $query = Item::with('customer', 'customer.tenant', 'maintenance', 'maintenance.tenant', 'maintenance.technician', 'maintenance.customer', 'maintenance.item', 'maintenance.user', 'maintenance.maintenance_detail.part')->whereRelation('maintenance', 'date_trans', '>=', $from_date)->whereRelation('maintenance', 'date_trans', '<=', $to_date);
        if ($tenant_id > 0) {
            $query = $query->whereRelation('maintenance', 'tenant_id', '=', $tenant_id);
        }

        if ($customer_id > 0) {
            $query = $query->whereRelation('maintenance', 'customer_id', '=', $customer_id);
        }

        $query = $query->withCount('maintenance');
        $query = $query->withMin('maintenance', 'date_trans');
        $query = $query->withMax('maintenance', 'date_trans');
        $query = $query->get();
        return response()->json($query);
    }
}

Yohohohohohooho | Sanrei Aya