|
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/ |
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\Models\Master\Item;
use App\Models\Trans\Maintenance;
class GlobalAPIDashboardController extends Controller
{
public function show_card() {
if (Auth::user()->model_type == 'App\Models\Master\Tenant') {
$tenant_id = Auth::user()->model_id;
} else if (Auth::user()->model_type == 'App\Models\Bussiness') {
$tenant_id = 0;
}
$query = DB::select("CALL sp_dashboard_show_card('".date('Y-m-d', strtotime(Carbon::now()))."', $tenant_id)");
$tenant = $query[0]->party;
$year = $query[0]->year;
$month = $query[0]->month;
$today = $query[0]->today;
return response()->json(['tenant' => $tenant, 'year' => $year, 'month' => $month, 'today' => $today]);
}
public function show_visit_monthly() {
if (Auth::user()->model_type == 'App\Models\Master\Tenant') {
$tenant_id = Auth::user()->model_id;
} else if (Auth::user()->model_type == 'App\Models\Bussiness') {
$tenant_id = 0;
}
$query = DB::select("CALL sp_dashboard_visit_monthly('".date('Y-m-d', strtotime(Carbon::now()))."', $tenant_id)");
return response()->json($query);
}
public function show_visit_customer() {
if (Auth::user()->model_type == 'App\Models\Master\Tenant') {
$tenant_id = Auth::user()->model_id;
} else if (Auth::user()->model_type == 'App\Models\Bussiness') {
$tenant_id = 0;
}
$query = DB::select("CALL sp_dashboard_visit_customer('".date('Y-m-d', strtotime(Carbon::now()))."', $tenant_id)");
return response()->json($query);
}
public function show_card_by_customer($customer_id) {
$query = DB::select("CALL sp_dashboard_show_card_customer('".date('Y-m-d', strtotime(Carbon::now()))."', $customer_id)");
$year = $query[0]->year;
$month = $query[0]->month;
$today = $query[0]->today;
return response()->json(['year' => $year, 'month' => $month, 'today' => $today]);
}
public function show_visit_monthly_by_customer($customer_id) {
$query = DB::select("CALL sp_dashboard_visit_monthly_customer('".date('Y-m-d', strtotime(Carbon::now()))."', $customer_id)");
return response()->json($query);
}
public function show_visit_item_customer($customer_id) {
$query = DB::select("CALL sp_dashboard_visit_item_customer('".date('Y-m-d', strtotime(Carbon::now()))."', $customer_id)");
return response()->json($query);
}
public function show_visit_history_item_customer($customer_id, $code) {
$query = Item::with('customer', 'customer.tenant', 'maintenance', 'maintenance.tenant', 'maintenance.technician', 'maintenance.customer', 'maintenance.item', 'maintenance.user', 'maintenance.maintenance_detail.part', 'last_maintenance.maintenance_detail', 'last_maintenance.technician');
if ($code != 'null') {
$query = $query->where('code', '=', $code);
}
$query = $query->where('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);
}
public function scan_barcode($item_code, $tenant_id, $customer_id) {
$query = Maintenance::with('item')
->whereRelation('item', 'code', $item_code);
if ($tenant_id != 0) {
$query = $query->where('tenant_id', '=', $tenant_id);
}
if ($customer_id != 0) {
$query = $query->where('customer_id', '=', $customer_id);
}
$minDate = $query->min('date_trans');
$maxDate = $query->max('date_trans');
$data = $query->first();
return response()->json([
'item_code' => $item_code,
'min_date_trans' => $minDate,
'max_date_trans' => $maxDate,
'data' => $data,
]);
}
}