feat(laporan-penilai-jaminan): penambahan fiture laporan penilai jaminan

This commit is contained in:
majid
2025-03-18 14:33:43 +07:00
parent 51d68b5c03
commit 23c85c1539
6 changed files with 805 additions and 48 deletions

View File

@@ -0,0 +1,128 @@
<?php
namespace Modules\Lpj\Exports;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Illuminate\Database\Eloquent\Builder;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Modules\Lpj\Models\Debiture;
use Modules\Lpj\Models\Permohonan;
class LaporanPenilaiJaminanExport implements FromQuery, WithHeadings, WithMapping, ShouldAutoSize
{
protected $tanggalAwal;
protected $tanggalAkhir;
protected $status;
protected $selectedIds;
public function __construct($tanggalAwal = null, $tanggalAkhir = null, $status = null, $selectedIds = null)
{
$this->tanggalAwal = $tanggalAwal;
$this->tanggalAkhir = $tanggalAkhir;
$this->status = $status;
$this->selectedIds = $selectedIds;
}
public function query()
{
$query = Permohonan::query()
->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'dokumenjaminan.jenisJaminan','nilaiPlafond', 'penilai']);
// Filter by date range if provided
if ($this->tanggalAwal && $this->tanggalAkhir) {
$query->whereBetween('tanggal_permohonan', [$this->tanggalAwal, $this->tanggalAkhir]);
}
$query->where('status', 'done');
// Filter by status if provided
if ($this->status) {
$types = is_array($this->status) ? $this->status : [$this->status];
$query->whereHas('penilai', function (Builder $query) use ($types) {
$query->whereIn('type_penilai', $types);
});
}
// Filter by selected IDs if provided
if ($this->selectedIds) {
$selectedIds = is_array($this->selectedIds) ? $this->selectedIds : explode(',', $this->selectedIds);
$query->whereIn('id', $selectedIds);
}
return $query;
}
public function map($row): array
{
$fieldPenilai = ['sederhana', 'standar', 'resume', 'memo', 'rap', 'call-report'];
$penilaiCek = null;
// Find the first available field in the array
foreach ($fieldPenilai as $value) {
if (!empty($row->penilai->$value)) {
$penilaiCek = $row->penilai->$value;
break;
}
}
$decodePenilai = json_decode($penilaiCek, true) ?? [];
return [
$row->id,
$row->nomor_registrasi,
$row->user->name,
$row->branch->name,
$row->tujuanPenilaian->name,
$row->debiture->name,
$row->penilai->type_penilai ?? '-',
'-',
$decodePenilai['luas_tanah'] ?? 0,
$decodePenilai['luas_bangunan'] ?? 0,
$decodePenilai['nilai_tanah_1'] ?? 0,
$decodePenilai['nilai_bangunan_1'] ?? 0,
$decodePenilai['total_nilai_pasar_wajar'] ?? 0,
$decodePenilai['likuidasi'] ?? 0,
$row->authorized_at,
$row->authorized_status ?? '-',
$row->authorized_by ?? '-',
$row->created_at,
];
}
public function headings(): array
{
return [
'ID',
'Nomor Registrasi',
'User Pemohon',
'Branch Pemohon',
'Tujuan Penilaian',
'Debitur',
'Jenis Laporan',
'Lokasi Jaminan',
'Luas Tanah',
'Luas Bangunan',
'Harga Tanah',
'Harga Bangunan',
'Nilai Pasar Wajar',
'Likuidasi',
'Tanggal Laporan',
'Nama Penilai',
'Nik Penilai',
];
}
public function columnFormats(): array
{
return [
'A' => NumberFormat::FORMAT_NUMBER,
'C' => NumberFormat::FORMAT_DATE_DATETIME,
'K' => NumberFormat::FORMAT_DATE_DATETIME,
'N' => NumberFormat::FORMAT_DATE_DATETIME
];
}
}