Files
sibedas/app/Models/PbgTaskDetail.php

253 lines
9.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Carbon\Carbon;
class PbgTaskDetail extends Model
{
protected $table = 'pbg_task_details';
protected $fillable = [
'pbg_task_uid',
'uid',
'nik',
'type_card',
'ownership',
'owner_name',
'ward_id',
'ward_name',
'district_id',
'district_name',
'regency_id',
'regency_name',
'province_id',
'province_name',
'address',
'owner_email',
'owner_phone',
'user',
'name',
'email',
'phone',
'user_nik',
'user_province_id',
'user_province_name',
'user_regency_id',
'user_regency_name',
'user_district_id',
'user_district_name',
'user_address',
'status',
'status_name',
'slf_status',
'slf_status_name',
'sppst_status',
'sppst_file',
'sppst_status_name',
'file_pbg',
'file_pbg_date',
'due_date',
'start_date',
'document_number',
'registration_number',
'function_type',
'application_type',
'application_type_name',
'consultation_type',
'condition',
'prototype',
'permanency',
'building_type',
'building_type_name',
'building_purpose',
'building_use',
'occupancy',
'name_building',
'total_area',
'area',
'area_type',
'height',
'floor',
'floor_area',
'basement',
'basement_height',
'basement_area',
'unit',
'prev_retribution',
'prev_pbg',
'prev_total_area',
'koefisien_dasar_bangunan',
'koefisien_lantai_bangunan',
'koefisien_lantai_hijau',
'koefisien_tapak_basement',
'ketinggian_bangunan',
'jalan_arteri',
'jalan_kolektor',
'jalan_bangunan',
'gsb',
'kkr_number',
'unit_data',
'is_mbr',
'code',
'building_ward_id',
'building_ward_name',
'building_district_id',
'building_district_name',
'building_regency_id',
'building_regency_name',
'building_province_id',
'building_province_name',
'building_address',
'latitude',
'longitude',
'building_photo',
'pbg_parent',
'api_created_at',
];
protected $casts = [
'unit_data' => 'array',
'is_mbr' => 'boolean',
'total_area' => 'decimal:2',
'area' => 'decimal:2',
'height' => 'decimal:2',
'floor_area' => 'decimal:2',
'basement_height' => 'decimal:2',
'basement_area' => 'decimal:2',
'prev_retribution' => 'decimal:2',
'prev_total_area' => 'decimal:2',
'koefisien_dasar_bangunan' => 'decimal:4',
'koefisien_lantai_bangunan' => 'decimal:4',
'koefisien_lantai_hijau' => 'decimal:4',
'koefisien_tapak_basement' => 'decimal:4',
'ketinggian_bangunan' => 'decimal:2',
'gsb' => 'decimal:2',
'latitude' => 'decimal:8',
'longitude' => 'decimal:8',
'file_pbg_date' => 'date',
'due_date' => 'date',
'start_date' => 'date',
'api_created_at' => 'datetime',
];
/**
* Get the PBG task that owns this detail
*/
public function pbgTask(): BelongsTo
{
return $this->belongsTo(PbgTask::class, 'pbg_task_uid', 'uuid');
}
/**
* Create or update PbgTaskDetail from API response
*/
public static function createFromApiResponse(array $data, string $pbgTaskUuid): self
{
$detailData = [
'pbg_task_uid' => $pbgTaskUuid,
'uid' => $data['uid'] ?? null,
'nik' => $data['nik'] ?? null,
'type_card' => $data['type_card'] ?? null,
'ownership' => $data['ownership'] ?? null,
'owner_name' => $data['owner_name'] ?? null,
'ward_id' => $data['ward_id'] ?? null,
'ward_name' => $data['ward_name'] ?? null,
'district_id' => $data['district_id'] ?? null,
'district_name' => $data['district_name'] ?? null,
'regency_id' => $data['regency_id'] ?? null,
'regency_name' => $data['regency_name'] ?? null,
'province_id' => $data['province_id'] ?? null,
'province_name' => $data['province_name'] ?? null,
'address' => $data['address'] ?? null,
'owner_email' => $data['owner_email'] ?? null,
'owner_phone' => $data['owner_phone'] ?? null,
'user' => $data['user'] ?? null,
'name' => $data['name'] ?? null,
'email' => $data['email'] ?? null,
'phone' => $data['phone'] ?? null,
'user_nik' => $data['user_nik'] ?? null,
'user_province_id' => $data['user_province_id'] ?? null,
'user_province_name' => $data['user_province_name'] ?? null,
'user_regency_id' => $data['user_regency_id'] ?? null,
'user_regency_name' => $data['user_regency_name'] ?? null,
'user_district_id' => $data['user_district_id'] ?? null,
'user_district_name' => $data['user_district_name'] ?? null,
'user_address' => $data['user_address'] ?? null,
'status' => $data['status'] ?? null,
'status_name' => $data['status_name'] ?? null,
'slf_status' => $data['slf_status'] ?? null,
'slf_status_name' => $data['slf_status_name'] ?? null,
'sppst_status' => $data['sppst_status'] ?? null,
'sppst_file' => $data['sppst_file'] ?? null,
'sppst_status_name' => $data['sppst_status_name'] ?? null,
'file_pbg' => $data['file_pbg'] ?? null,
'file_pbg_date' => isset($data['file_pbg_date']) ? Carbon::parse($data['file_pbg_date'])->format('Y-m-d') : null,
'due_date' => isset($data['due_date']) ? Carbon::parse($data['due_date'])->format('Y-m-d') : null,
'start_date' => isset($data['start_date']) ? Carbon::parse($data['start_date'])->format('Y-m-d') : null,
'document_number' => $data['document_number'] ?? null,
'registration_number' => $data['registration_number'] ?? null,
'function_type' => $data['function_type'] ?? null,
'application_type' => $data['application_type'] ?? null,
'application_type_name' => $data['application_type_name'] ?? null,
'consultation_type' => $data['consultation_type'] ?? null,
'condition' => $data['condition'] ?? null,
'prototype' => $data['prototype'] ?? null,
'permanency' => $data['permanency'] ?? null,
'building_type' => $data['building_type'] ?? null,
'building_type_name' => $data['building_type_name'] ?? null,
'building_purpose' => $data['building_purpose'] ?? null,
'building_use' => $data['building_use'] ?? null,
'occupancy' => $data['occupancy'] ?? null,
'name_building' => $data['name_building'] ?? null,
'total_area' => $data['total_area'] ?? null,
'area' => $data['area'] ?? null,
'area_type' => $data['area_type'] ?? null,
'height' => $data['height'] ?? null,
'floor' => $data['floor'] ?? null,
'floor_area' => $data['floor_area'] ?? null,
'basement' => $data['basement'] ?? null,
'basement_height' => $data['basement_height'] ?? null,
'basement_area' => $data['basement_area'] ?? null,
'unit' => $data['unit'] ?? null,
'prev_retribution' => $data['prev_retribution'] ?? null,
'prev_pbg' => $data['prev_pbg'] ?? null,
'prev_total_area' => $data['prev_total_area'] ?? null,
'koefisien_dasar_bangunan' => $data['koefisien_dasar_bangunan'] ?? null,
'koefisien_lantai_bangunan' => $data['koefisien_lantai_bangunan'] ?? null,
'koefisien_lantai_hijau' => $data['koefisien_lantai_hijau'] ?? null,
'koefisien_tapak_basement' => $data['koefisien_tapak_basement'] ?? null,
'ketinggian_bangunan' => $data['ketinggian_bangunan'] ?? null,
'jalan_arteri' => $data['jalan_arteri'] ?? null,
'jalan_kolektor' => $data['jalan_kolektor'] ?? null,
'jalan_bangunan' => $data['jalan_bangunan'] ?? null,
'gsb' => $data['gsb'] ?? null,
'kkr_number' => $data['kkr_number'] ?? null,
'unit_data' => $data['unit_data'] ?? null,
'is_mbr' => $data['is_mbr'] ?? false,
'code' => $data['code'] ?? null,
'building_ward_id' => $data['building_ward_id'] ?? null,
'building_ward_name' => $data['building_ward_name'] ?? null,
'building_district_id' => $data['building_district_id'] ?? null,
'building_district_name' => $data['building_district_name'] ?? null,
'building_regency_id' => $data['building_regency_id'] ?? null,
'building_regency_name' => $data['building_regency_name'] ?? null,
'building_province_id' => $data['building_province_id'] ?? null,
'building_province_name' => $data['building_province_name'] ?? null,
'building_address' => $data['building_address'] ?? null,
'latitude' => $data['latitude'] ?? null,
'longitude' => $data['longitude'] ?? null,
'building_photo' => $data['building_photo'] ?? null,
'pbg_parent' => $data['pbg_parent'] ?? null,
'api_created_at' => isset($data['created_at']) ? Carbon::parse($data['created_at'])->format('Y-m-d H:i:s') : null,
];
return static::updateOrCreate(
['uid' => $data['uid']],
$detailData
);
}
}