Compare commits
95 Commits
lpj-db-mig
...
tender
| Author | SHA1 | Date | |
|---|---|---|---|
| 0df676fa5e | |||
| 1c35d932d3 | |||
| 6ad34ee019 | |||
| 0e3b4786c4 | |||
| 88bf73cbb9 | |||
| dc9bdda8b0 | |||
| 7b885d7d45 | |||
| bb1bc50c0b | |||
| ae678d6c5d | |||
| 5c9147c87d | |||
| 6b344d353d | |||
| f4549b4f7f | |||
| 7b5ecf2a5d | |||
| 8209ed830e | |||
| ff1b7e009c | |||
| 04baf15d94 | |||
| 35820e2f1a | |||
| fcd550bc6e | |||
| 31ec6f1c53 | |||
| 5821e22fff | |||
| 20ab9d595b | |||
| 12cc57c47d | |||
| 2db3169e2d | |||
| 12252ad791 | |||
| b20e950c3c | |||
| d9d99f7108 | |||
| 150e5c2288 | |||
| d6719f7a5e | |||
| 0a74584652 | |||
| 7dcff96536 | |||
| 399217e102 | |||
|
|
c1751169ac | ||
| 8ad77cdc1a | |||
| 503242d8dc | |||
| fc5f62233c | |||
| 769b4f733b | |||
| 26155c3b09 | |||
| 57a1dbbf4d | |||
| 547eb6d6b6 | |||
| 3aa8311f61 | |||
| 32b08281ed | |||
| e05301be6c | |||
| b53a8da804 | |||
| 6de3e9c366 | |||
| 0a3c2c4021 | |||
| 6a01aa1663 | |||
| 6ee362e343 | |||
| 836ad0595d | |||
| 38b544115b | |||
| f97df3f902 | |||
| 4a4b168084 | |||
| 38390eb8b2 | |||
| 89eb428688 | |||
| 8fb4025ae2 | |||
| 0eb2009153 | |||
| 9d93979a8b | |||
| 45a8fac8e1 | |||
| b468d05c38 | |||
| f81fe0dcfc | |||
| 0e790ae72f | |||
| 36ccec30f7 | |||
| a0bb9a4fdb | |||
| f428ef3165 | |||
| ec1ad33b60 | |||
| ea315cadbe | |||
| 034733d2b5 | |||
| 2a8ac760f2 | |||
| fe5fb2deae | |||
| 690bbcbf1f | |||
| 3e4a7de80e | |||
| fe3b3c5221 | |||
| 3e11e17f31 | |||
| b7113ca7a0 | |||
| 325a711ea4 | |||
| e8c1f8439a | |||
| 5290e9c59b | |||
| be1b73b284 | |||
| e7710b5a8a | |||
| 224d830f89 | |||
| 575573f1ef | |||
| 9b43dbdb8a | |||
| f6d6e0ddf2 | |||
| 9082f97baf | |||
| 9908cbe3b0 | |||
| 63e91023be | |||
| 0614905cda | |||
| 87e1af60a5 | |||
| 5e65264bd7 | |||
| e71ff5ed3e | |||
| 8585414c00 | |||
| 794aed812d | |||
| 08641e9cd7 | |||
| c8620c9002 | |||
| 8789718e7a | |||
| 3af9a7b67b |
@@ -13,7 +13,6 @@ use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanHasilPenilaianJaminanInternalExternalExport implements FromCollection, WithHeadings, WithMapping, WithTitle, WithCustomStartCell, WithEvents
|
||||
{
|
||||
@@ -31,20 +30,10 @@ class LaporanHasilPenilaianJaminanInternalExternalExport implements FromCollecti
|
||||
|
||||
// Apply date range filter if provided
|
||||
if ($this->request->has('start_date') || $this->request->has('end_date')) {
|
||||
$startDate = $this->request->start_date ?? '1900-01-01';
|
||||
$endDate = $this->request->end_date ?? now()->toDateString();
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
// OR check if has penawaran with date in range
|
||||
$q->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
});
|
||||
$query->whereBetween('tanggal_permohonan', [
|
||||
$this->request->start_date ?? '1900-01-01',
|
||||
$this->request->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
// Apply branch filter if provided
|
||||
@@ -67,8 +56,6 @@ class LaporanHasilPenilaianJaminanInternalExternalExport implements FromCollecti
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search) . '%');
|
||||
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
@@ -108,13 +95,13 @@ class LaporanHasilPenilaianJaminanInternalExternalExport implements FromCollecti
|
||||
return [
|
||||
$this->rowNumber,
|
||||
$permohonan->nomor_registrasi,
|
||||
$permohonan->tanggal_permohonan ?? '',
|
||||
$permohonan->debiture->branch->name ?? '',
|
||||
$permohonan->user->name ?? $permohonan->mig_nama_ao ?? '',
|
||||
$permohonan->debiture->cif ?? '',
|
||||
$permohonan->debiture->name ?? '',
|
||||
$permohonan->tanggal_permohonan,
|
||||
$permohonan->debiture->branch->name,
|
||||
$permohonan->creator->name,
|
||||
$permohonan->debiture->cif,
|
||||
$permohonan->debiture->name,
|
||||
$permohonan->jenisPenilaian->name,
|
||||
$permohonan->tujuanPenilaian->name,
|
||||
$permohonan->jenisPenilaian->name ?? '',
|
||||
$permohonan->jenisFasilitasKredit->name,
|
||||
$permohonan->documents->pluck('jenisJaminan.name')->unique()->implode(', '),
|
||||
$permohonan->documents->map(function ($document) {
|
||||
@@ -141,18 +128,14 @@ class LaporanHasilPenilaianJaminanInternalExternalExport implements FromCollecti
|
||||
'', // tanggal_spk
|
||||
'', // nomor_spk
|
||||
'', // tanggal_rencana_kunjungan
|
||||
$permohonan->penilaian && $permohonan->penilaian->tanggal_kunjungan
|
||||
? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan)
|
||||
: '',
|
||||
$permohonan->penilaian->tanggal_kunjungan ? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan) : '',
|
||||
'', // tanggal_delivered
|
||||
'', // jangka_waktu_sla
|
||||
($permohonan->approval_dd_at || $permohonan->approval_eo_at) ?
|
||||
formatTanggalIndonesia($permohonan->approval_dd_at ?? $permohonan->approval_eo_at) : '',
|
||||
$permohonan->penilaian && $permohonan->penilaian->tanggal_kunjungan
|
||||
? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan)
|
||||
: '',
|
||||
$permohonan->penilaian->tanggal_kunjungan ? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan) : '',
|
||||
$permohonan->penilaian->_user_penilai->userPenilaiTeam->name ?? '',
|
||||
$permohonan->approveSo->name ?? '',
|
||||
$permohonan->penilaian->teams ?? '',
|
||||
'', // saran
|
||||
'' // catatan
|
||||
];
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Modules\Lpj\Exports;
|
||||
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
@@ -12,299 +11,167 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Helpers\Lpj;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanPenilaiJaminanExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
|
||||
class LaporanPenilaiJaminanExport implements FromQuery, WithHeadings, WithMapping, ShouldAutoSize
|
||||
{
|
||||
protected $tanggalAwal;
|
||||
protected $tanggalAkhir;
|
||||
protected $status;
|
||||
protected $selectedIds;
|
||||
|
||||
protected $request;
|
||||
|
||||
public function __construct($request)
|
||||
public function __construct($tanggalAwal = null, $tanggalAkhir = null, $status = null, $selectedIds = null)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->tanggalAwal = $tanggalAwal;
|
||||
$this->tanggalAkhir = $tanggalAkhir;
|
||||
$this->status = $status;
|
||||
$this->selectedIds = $selectedIds;
|
||||
}
|
||||
|
||||
|
||||
public function collection()
|
||||
public function query()
|
||||
{
|
||||
$query = Permohonan::query();
|
||||
$query = $query->where('status', 'done');
|
||||
$query = Permohonan::query()
|
||||
->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'dokumenjaminan.jenisJaminan','nilaiPlafond', 'penilai', 'inspeksi']);
|
||||
|
||||
// Apply date range filter if provided
|
||||
if ($this->request->has('start_date') || $this->request->has('end_date')) {
|
||||
$startDate = $this->request->start_date ?? '1900-01-01';
|
||||
$endDate = $this->request->end_date ?? now()->toDateString();
|
||||
// Filter by date range if provided
|
||||
if ($this->tanggalAwal && $this->tanggalAkhir) {
|
||||
$query->whereBetween('tanggal_permohonan', [$this->tanggalAwal, $this->tanggalAkhir]);
|
||||
}
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
// OR check if has penawaran with date in range
|
||||
$q->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
$query->where('status', 'done');
|
||||
// Filter by status if provided
|
||||
if ($this->status) {
|
||||
$types = is_array($this->status) ? $this->status : [$this->status];
|
||||
$types = array_map('strtolower', $types);
|
||||
$query->whereHas('penilai', function (Builder $query) use ($types) {
|
||||
$query->whereIn('type_penilai', $types);
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by laporan type if provided
|
||||
if ($this->request->has('laporan') && is_array($this->request->laporan) && !empty($this->request->laporan)) {
|
||||
foreach ($this->request->laporan as $type) {
|
||||
$query->whereHas('penilai', function ($q) use ($type) {
|
||||
$q->where('type_penilai', 'LIKE', '%' . $type . '%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Apply branch filter if provided
|
||||
if ($this->request->has('branch_id') && !empty($this->request->branch_id)) {
|
||||
$query->where('branch_id', $this->request->branch_id);
|
||||
}
|
||||
|
||||
// Filter by selected IDs if provided
|
||||
if ($this->request->has('selected_ids') && !empty($this->request->selected_ids)) {
|
||||
$selectedIds = is_array($this->request->selected_ids) ? $this->request->selected_ids : explode(',', $this->request->selected_ids);
|
||||
if ($this->selectedIds) {
|
||||
$selectedIds = is_array($this->selectedIds) ? $this->selectedIds : explode(',', $this->selectedIds);
|
||||
$query->whereIn('id', $selectedIds);
|
||||
}
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($this->request->has('search') && !empty($this->request->search)) {
|
||||
$search = $this->request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search) . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Default ordering
|
||||
$query->orderBy('nomor_registrasi', 'asc');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
protected $rowNumber = 0;
|
||||
public function map($permohonan): array
|
||||
public function map($row): array
|
||||
{
|
||||
$this->rowNumber++;
|
||||
$luas_tanah = 0;
|
||||
$luas_bangunan = 0;
|
||||
$nilai_tanah = 0;
|
||||
$nilai_bangunan = 0;
|
||||
$npw = 0;
|
||||
$nilai_liquidasi = 0;
|
||||
|
||||
if (isset($permohonan->penilai->lpj)) {
|
||||
$lpj = json_decode($permohonan->penilai->lpj, true);
|
||||
$npw = str_replace('.', '', $lpj['total_nilai_pasar_wajar'] ?? 0);
|
||||
// ambil data alamat dari inspeksi
|
||||
$alamat_inspeksi = null;
|
||||
|
||||
$luas_tanah = $lpj['luas_tanah'] ?? 0;
|
||||
$luas_bangunan = $lpj['luas_bangunan'] ?? 0;
|
||||
$nilai_tanah = str_replace('.', '', $lpj['nilai_tanah_2'] ?? 0);
|
||||
$nilai_bangunan = str_replace('.', '', $lpj['nilai_bangunan_2'] ?? 0);
|
||||
$nilai_liquidasi = str_replace('.', '', $lpj['likuidasi_nilai_2'] ?? 0);
|
||||
if ($row->inspeksi) {
|
||||
$alamat_inspeksi = json_decode($row->inspeksi->data_form, true) ?? null;
|
||||
$alamat_inspeksi = $alamat_inspeksi['asset']['alamat']['sesuai'] ?? $alamat_inspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
}
|
||||
$alamat_inspeksi = $alamat_inspeksi['address'] ?? '-';
|
||||
|
||||
|
||||
// ambil data dari table penilai
|
||||
$fieldPenilai = ['lpj', 'resume', 'memo', 'rap', 'call-report'];
|
||||
$penilaiCek = null;
|
||||
|
||||
// Cari field yang tersedia
|
||||
foreach ($fieldPenilai as $value) {
|
||||
if (!empty($row->penilai->$value)) {
|
||||
$penilaiCek = $row->penilai->$value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$decodePenilai = json_decode($penilaiCek, true) ?? [];
|
||||
// Ambil nilai utama
|
||||
$luasTanah = $decodePenilai['luas_tanah'] ?? 0;
|
||||
$nilaiTanah1 = $decodePenilai['nilai_tanah_1'] ?? 0;
|
||||
$luasBangunan = $decodePenilai['luas_bangunan'] ?? 0;
|
||||
$nilaiBangunan1 = $decodePenilai['nilai_bangunan_1'] ?? 0;
|
||||
$totalNilaiPasar = $decodePenilai['total_nilai_pasar_wajar'] ?? 0;
|
||||
$likuidasi = $decodePenilai['likuidasi'] ?? 0;
|
||||
|
||||
// Ambil data npw_tambahan jika ada
|
||||
$npwTambahan = $decodePenilai['npw_tambahan'] ?? [];
|
||||
$tambahanDetails = [];
|
||||
foreach ($npwTambahan as $tambahan) {
|
||||
$tambahanDetails[] = sprintf(
|
||||
'%s: Luas: %s, Nilai 1: %s, Nilai 2: %s',
|
||||
$tambahan['name'] ?? '-',
|
||||
$tambahan['luas'] ?? 0,
|
||||
$tambahan['nilai_1'] ?? 0,
|
||||
$tambahan['nilai_2'] ?? 0
|
||||
);
|
||||
}
|
||||
$tambahanSummary = implode("; ", $tambahanDetails);
|
||||
|
||||
// Ambil data penilaian dari table penilaian
|
||||
$user_penilai = $row->penilaian->userPenilai ?? null;
|
||||
$user_penilai_name = null;
|
||||
foreach ($user_penilai as $value) {
|
||||
if ($value->role == 'penilai') {
|
||||
$user_penilai_name = $value->user->name;
|
||||
$nik_penilai = $value->user->nik ?? '-';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
$this->rowNumber,
|
||||
$permohonan->nomor_registrasi,
|
||||
$permohonan->tanggal_permohonan ?? '',
|
||||
$permohonan->debiture->branch->name ?? '',
|
||||
$permohonan->user->name ?? $permohonan->mig_nama_ao ?? '',
|
||||
$permohonan->debiture->cif ?? '',
|
||||
$permohonan->debiture->name ?? '',
|
||||
$permohonan->tujuanPenilaian->name,
|
||||
$permohonan->jenisPenilaian->name ?? '',
|
||||
$permohonan->jenisFasilitasKredit->name,
|
||||
$permohonan->documents->pluck('jenisJaminan.name')->unique()->implode(', '),
|
||||
$permohonan->documents->map(function ($document) {
|
||||
return formatAlamat($document);
|
||||
})->unique()->implode(', '),
|
||||
$permohonan->documents->flatMap(function ($document) {
|
||||
return $document->detail->map(function ($detail) {
|
||||
return (!empty($detail->dokumen_nomor) && is_array($detail->dokumen_nomor))
|
||||
? ($detail->jenisLegalitasJaminan->name ?? '') . "\n" . implode(', ', $detail->dokumen_nomor)
|
||||
: null;
|
||||
});
|
||||
})->filter()->unique()->implode(', '),
|
||||
$permohonan->documents->pluck('pemilik.name')->unique()->implode(', '),
|
||||
$luas_tanah . ' m²',
|
||||
formatRupiah($nilai_tanah, 2),
|
||||
$luas_bangunan . ' m²',
|
||||
formatRupiah($nilai_bangunan, 2),
|
||||
formatRupiah($permohonan->nilai_njop ?? 0, 2),
|
||||
formatRupiah($npw, 2),
|
||||
formatRupiah($nilai_liquidasi, 2),
|
||||
$permohonan->documents->map(function ($document) {
|
||||
return formatTanggalIndonesia($document->created_at);
|
||||
})->first(),
|
||||
'', // tanggal_spk
|
||||
'', // nomor_spk
|
||||
'', // tanggal_rencana_kunjungan
|
||||
$permohonan->penilaian && $permohonan->penilaian->tanggal_kunjungan
|
||||
? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan)
|
||||
: '',
|
||||
'', // tanggal_delivered
|
||||
'', // jangka_waktu_sla
|
||||
($permohonan->approval_dd_at || $permohonan->approval_eo_at) ?
|
||||
formatTanggalIndonesia($permohonan->approval_dd_at ?? $permohonan->approval_eo_at) : '',
|
||||
$permohonan->penilaian && $permohonan->penilaian->tanggal_kunjungan
|
||||
? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan)
|
||||
: '',
|
||||
$permohonan->penilaian->_user_penilai->userPenilaiTeam->name ?? '',
|
||||
$permohonan->approveSo->name ?? '',
|
||||
$permohonan->penilai->type_penilai?? '',
|
||||
$row->id,
|
||||
$row->nomor_registrasi,
|
||||
$row->user->name,
|
||||
$row->branch->name,
|
||||
$row->tujuanPenilaian->name,
|
||||
$row->debiture->name,
|
||||
$row->penilai->type_penilai ?? '-',
|
||||
$alamat_inspeksi ?? '-',
|
||||
$luasTanah,
|
||||
$luasBangunan,
|
||||
$nilaiTanah1,
|
||||
$nilaiBangunan1,
|
||||
$totalNilaiPasar,
|
||||
$likuidasi,
|
||||
$row->laporan->created_at ?? '-',
|
||||
$user_penilai_name,
|
||||
$nik_penilai,
|
||||
$row->created_at,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'No',
|
||||
'ID',
|
||||
'Nomor Registrasi',
|
||||
'Tanggal Permohonan',
|
||||
'User Pemohon',
|
||||
'Cabang',
|
||||
'Pemohon',
|
||||
'CIF',
|
||||
'Nama Debitur',
|
||||
'Jenis Penilaian',
|
||||
'Tujuan Penilaian',
|
||||
'Jenis Fasilitas Kredit',
|
||||
'Jenis Agunan',
|
||||
'Alamat Agunan',
|
||||
'Bukti Kepemilikan',
|
||||
'Nama Pemilik',
|
||||
'Debitur',
|
||||
'Jenis Laporan',
|
||||
'Lokasi Jaminan',
|
||||
'Luas Tanah',
|
||||
'Nilai Tanah',
|
||||
'Luas Bangunan',
|
||||
'Nilai Bangunan',
|
||||
'Nilai NJOP',
|
||||
'Harga Tanah',
|
||||
'Harga Bangunan',
|
||||
'Nilai Pasar Wajar',
|
||||
'Nilai Likuidasi',
|
||||
'Tanggal Dokumen Diterima',
|
||||
'Tanggal SPK',
|
||||
'Nomor SPK',
|
||||
'Tanggal Rencana Kunjungan',
|
||||
'Tanggal Kunjungan',
|
||||
'Tanggal Delivered',
|
||||
'Jangka Waktu SLA',
|
||||
'Likuidasi',
|
||||
'Tanggal Laporan',
|
||||
'Tanggal Review',
|
||||
'Nama Penilai',
|
||||
'Nama Team Leader',
|
||||
'Laporan',
|
||||
|
||||
'Nik Penilai',
|
||||
'Created At',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Laporan Hasil Penilaian Jaminan Internal & External';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A7';
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
// Get the sheet
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
|
||||
// Set the title
|
||||
$sheet->setCellValue('A1', 'LAPORAN PENILAIAN JAMINAN');
|
||||
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
|
||||
|
||||
// Merge cells for title
|
||||
$sheet->mergeCells('A1:AH1');
|
||||
$sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set the branch information if filtered
|
||||
$branchInfo = '';
|
||||
if ($this->request->has('branch_id') && !empty($this->request->branch_id)) {
|
||||
$branch = Branch::find($this->request->branch_id);
|
||||
if ($branch) {
|
||||
$branchInfo = 'Cabang: ' . $branch->name;
|
||||
$sheet->setCellValue('A2', $branchInfo);
|
||||
$sheet->mergeCells('A2:AH2');
|
||||
$sheet->getStyle('A2')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
$sheet->getStyle('A2')->getFont()->setBold(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the period
|
||||
$startDate = $this->request->start_date ?? '';
|
||||
$endDate = $this->request->end_date ?? '';
|
||||
|
||||
$rowIndex = $branchInfo ? 3 : 2;
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$startDateFormatted = Carbon::parse($startDate)->format('d F Y');
|
||||
$endDateFormatted = Carbon::parse($endDate)->format('d F Y');
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Periode: ' . $startDateFormatted . ' - ' . $endDateFormatted);
|
||||
} else {
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Periode: Semua Data');
|
||||
}
|
||||
$sheet->mergeCells('A' . $rowIndex . ':AH' . $rowIndex);
|
||||
$sheet->getStyle('A' . $rowIndex)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set the date of export
|
||||
$rowIndex++;
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Tanggal Export: ' . Carbon::now()->format('d F Y H:i:s'));
|
||||
|
||||
// Set the user who exported
|
||||
$rowIndex++;
|
||||
$userName = Auth::user() ? Auth::user()->name : 'System';
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Diexport oleh: ' . $userName);
|
||||
|
||||
// Add a blank line
|
||||
$rowIndex++;
|
||||
$sheet->setCellValue('A' . $rowIndex, '');
|
||||
|
||||
// Style the header row
|
||||
$headerRange = 'A7:' . $sheet->getHighestColumn() . '7';
|
||||
$sheet->getStyle($headerRange)->getFont()->setBold(true);
|
||||
$sheet->getStyle($headerRange)->getFill()
|
||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||
->getStartColor()->setARGB('FFCCCCCC');
|
||||
|
||||
// Auto-size columns - fixed to handle columns beyond Z
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
|
||||
|
||||
for ($i = 1; $i <= $highestColumnIndex; $i++) {
|
||||
$currentColumn = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($currentColumn)->setAutoSize(true);
|
||||
}
|
||||
|
||||
// Add borders to all cells with data
|
||||
$dataRange = 'A7:' . $sheet->getHighestColumn() . $sheet->getHighestRow();
|
||||
$sheet->getStyle($dataRange)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
|
||||
|
||||
// Center align the header row
|
||||
$sheet->getStyle($headerRange)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set text wrap for header cells
|
||||
$sheet->getStyle($headerRange)->getAlignment()->setWrapText(true);
|
||||
},
|
||||
'A' => NumberFormat::FORMAT_NUMBER,
|
||||
'C' => NumberFormat::FORMAT_DATE_DATETIME,
|
||||
'K' => NumberFormat::FORMAT_DATE_DATETIME,
|
||||
'N' => NumberFormat::FORMAT_DATE_DATETIME
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanPenilaianJaminanExport implements FromCollection, WithHeadings, WithMapping, WithTitle, WithCustomStartCell, WithEvents
|
||||
{
|
||||
protected $request;
|
||||
@@ -30,22 +30,10 @@ class LaporanPenilaianJaminanExport implements FromCollection, WithHeadings, Wit
|
||||
|
||||
// Apply date range filter if provided
|
||||
if ($this->request->has('start_date') || $this->request->has('end_date')) {
|
||||
|
||||
$startDate = $this->request->start_date ?? '1900-01-01';
|
||||
$endDate = $this->request->end_date ?? now()->toDateString();
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
// OR check if has penawaran with date in range
|
||||
$q->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
});
|
||||
|
||||
$query->whereBetween('tanggal_permohonan', [
|
||||
$this->request->start_date ?? '1900-01-01',
|
||||
$this->request->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
// Apply branch filter if provided
|
||||
@@ -67,7 +55,6 @@ class LaporanPenilaianJaminanExport implements FromCollection, WithHeadings, Wit
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search) . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search . '%');
|
||||
@@ -79,8 +66,6 @@ class LaporanPenilaianJaminanExport implements FromCollection, WithHeadings, Wit
|
||||
// Default ordering
|
||||
$query->orderBy('nomor_registrasi', 'asc');
|
||||
|
||||
dd($query->toSql(), $query->getBindings());
|
||||
|
||||
return $query->with(['debiture.branch'])->get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanUserLimitExport implements FromCollection, WithHeadings, WithMapping, WithTitle, WithCustomStartCell, WithEvents
|
||||
{
|
||||
protected $request;
|
||||
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$query = Permohonan::query();
|
||||
$query = $query->where('status', 'done');
|
||||
|
||||
// Apply date range filter if provided
|
||||
if ($this->request->has('start_date') || $this->request->has('end_date')) {
|
||||
$startDate = $this->request->start_date ?? '1900-01-01';
|
||||
$endDate = $this->request->end_date ?? now()->toDateString();
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
// OR check if has penawaran with date in range
|
||||
$q->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Apply branch filter if provided
|
||||
if ($this->request->has('branch_id') && !empty($this->request->branch_id)) {
|
||||
$query->where('branch_id', $this->request->branch_id);
|
||||
}
|
||||
|
||||
if ($this->request->has('penilai_id') && !empty($this->request->penilai_id)) {
|
||||
$request = $this->request; // Store in a local variable
|
||||
$query->whereHas('penilaian._user_penilai.userPenilaiTeam', function ($q) use ($request) {
|
||||
$q->where('user_id', $request->penilai_id);
|
||||
});
|
||||
}
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($this->request->has('search') && !empty($this->request->search)) {
|
||||
$search = $this->request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search) . '%');
|
||||
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
// Default ordering
|
||||
$query->orderBy('nomor_registrasi', 'asc');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
protected $rowNumber = 0;
|
||||
|
||||
public function map($permohonan): array
|
||||
{
|
||||
$this->rowNumber++;
|
||||
$npw = 0;
|
||||
|
||||
if (isset($permohonan->penilai->lpj)) {
|
||||
$lpj = json_decode($permohonan->penilai->lpj, true);
|
||||
$npw = str_replace('.', '', $lpj['total_nilai_pasar_wajar'] ?? 0);
|
||||
}
|
||||
|
||||
return [
|
||||
$this->rowNumber,
|
||||
$permohonan->nomor_registrasi,
|
||||
$permohonan->debiture->branch->name ?? '',
|
||||
$permohonan->debiture->name ?? '',
|
||||
$permohonan->user->name ?? $permohonan->mig_nama_ao ?? '',
|
||||
$permohonan->tanggal_permohonan ?? '',
|
||||
$permohonan->penilaian->_user_penilai->userPenilaiTeam->name ?? '',
|
||||
$permohonan->penilaian && $permohonan->penilaian->tanggal_kunjungan
|
||||
? formatTanggalIndonesia($permohonan->penilaian->tanggal_kunjungan)
|
||||
: '',
|
||||
formatRupiah($npw, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'No',
|
||||
'Nomor Registrasi',
|
||||
'Cabang',
|
||||
'Nama Debitur',
|
||||
'Pemohon',
|
||||
'Tanggal Permohonan',
|
||||
'Nama Penilai',
|
||||
'Tanggal Laporan',
|
||||
'Nilai Pasar Wajar',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Laporan User Limit';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A7';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
// Get the sheet
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
|
||||
// Set the title
|
||||
$sheet->setCellValue('A1', 'LAPORAN PENILAIAN JAMINAN');
|
||||
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
|
||||
|
||||
// Merge cells for title
|
||||
$sheet->mergeCells('A1:AH1');
|
||||
$sheet->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set the branch information if filtered
|
||||
$branchInfo = '';
|
||||
if ($this->request->has('branch_id') && !empty($this->request->branch_id)) {
|
||||
$branch = Branch::find($this->request->branch_id);
|
||||
if ($branch) {
|
||||
$branchInfo = 'Cabang: ' . $branch->name;
|
||||
$sheet->setCellValue('A2', $branchInfo);
|
||||
$sheet->mergeCells('A2:AH2');
|
||||
$sheet->getStyle('A2')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
$sheet->getStyle('A2')->getFont()->setBold(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the period
|
||||
$startDate = $this->request->start_date ?? '';
|
||||
$endDate = $this->request->end_date ?? '';
|
||||
|
||||
$rowIndex = $branchInfo ? 3 : 2;
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$startDateFormatted = Carbon::parse($startDate)->format('d F Y');
|
||||
$endDateFormatted = Carbon::parse($endDate)->format('d F Y');
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Periode: ' . $startDateFormatted . ' - ' . $endDateFormatted);
|
||||
} else {
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Periode: Semua Data');
|
||||
}
|
||||
$sheet->mergeCells('A' . $rowIndex . ':AH' . $rowIndex);
|
||||
$sheet->getStyle('A' . $rowIndex)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set the date of export
|
||||
$rowIndex++;
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Tanggal Export: ' . Carbon::now()->format('d F Y H:i:s'));
|
||||
|
||||
// Set the user who exported
|
||||
$rowIndex++;
|
||||
$userName = Auth::user() ? Auth::user()->name : 'System';
|
||||
$sheet->setCellValue('A' . $rowIndex, 'Diexport oleh: ' . $userName);
|
||||
|
||||
// Add a blank line
|
||||
$rowIndex++;
|
||||
$sheet->setCellValue('A' . $rowIndex, '');
|
||||
|
||||
// Style the header row
|
||||
$headerRange = 'A7:' . $sheet->getHighestColumn() . '7';
|
||||
$sheet->getStyle($headerRange)->getFont()->setBold(true);
|
||||
$sheet->getStyle($headerRange)->getFill()
|
||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||
->getStartColor()->setARGB('FFCCCCCC');
|
||||
|
||||
// Auto-size columns - fixed to handle columns beyond Z
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
|
||||
|
||||
for ($i = 1; $i <= $highestColumnIndex; $i++) {
|
||||
$currentColumn = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($currentColumn)->setAutoSize(true);
|
||||
}
|
||||
|
||||
// Add borders to all cells with data
|
||||
$dataRange = 'A7:' . $sheet->getHighestColumn() . $sheet->getHighestRow();
|
||||
$sheet->getStyle($dataRange)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
|
||||
|
||||
// Center align the header row
|
||||
$sheet->getStyle($headerRange)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
// Set text wrap for header cells
|
||||
$sheet->getStyle($headerRange)->getAlignment()->setWrapText(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\TeamsUsers;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
function formatTanggalIndonesia($date, $time = false)
|
||||
{
|
||||
@@ -532,160 +530,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
function parsePembandingMigration($keterangan) {
|
||||
$keterangan = preg_replace('/[-]{5,}/', '',$keterangan); // Hapus ------
|
||||
$keterangan = preg_replace('/[.]{5,}/', '',$keterangan); // Hapus .....
|
||||
|
||||
$keterangan = preg_replace('/\s+/', ' ',$keterangan);
|
||||
$keterangan = preg_replace('/\s*\n\s*/', "\n",$keterangan);
|
||||
|
||||
// Pecah teks per baris untuk diproses
|
||||
$lines = explode("\n",$keterangan);
|
||||
$cleaned = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (!empty($line)) {
|
||||
// Format angka dalam format Rp. 123.456.789
|
||||
$line = preg_replace_callback('/Rp\.\s*([\d.,]+)/', function($matches) {
|
||||
$angka = str_replace(['.', ','], '', $matches[1]);
|
||||
return 'Rp. ' . number_format((int)$angka, 0, ',', '.');
|
||||
}, $line);
|
||||
|
||||
// Jika ada tanda pagar (#), pisahkan menjadi baris baru
|
||||
$line = str_replace('#', "\n#", $line);
|
||||
|
||||
$cleaned[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n", $cleaned);
|
||||
}
|
||||
/**
|
||||
* get full path to internal storage file or external storage file
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
|
||||
function getFilePath($path)
|
||||
function formatNotifikasi($notifikasi)
|
||||
{
|
||||
// define base path external storage (use .env) example: 'F:\path\to\storage' in windows
|
||||
$externalBase = env('EXTERNAL_STORAGE_BASE_PATH', 'F:LPJ/lpj/LPJ Gambar/001/');
|
||||
|
||||
$segments = explode('/', $path);
|
||||
|
||||
if(strtoupper($segments[0]) === 'SURVEYOR'){
|
||||
$year = $segments[1];
|
||||
$month = ucfirst(strtolower($segments[2]));
|
||||
$date = $segments[3];
|
||||
$code = $segments[4];
|
||||
$file = $segments[5] ?? '';
|
||||
|
||||
$extenalFullpath = $externalBase . $year . '/' . $month . '/' . $date . '/' . $code . '/' . $file;
|
||||
|
||||
if(File::exists($extenalFullpath)){
|
||||
return $extenalFullpath;
|
||||
}
|
||||
}
|
||||
|
||||
// if not found in external storage, try to find in internal storage
|
||||
if (Storage::exists($path)) {
|
||||
return Storage::url('app/' . $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
if (!$timestamp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Trim whitespace dan normalize
|
||||
$timestamp = trim($timestamp);
|
||||
|
||||
// Log untuk debugging
|
||||
Log::info('Mencoba parsing timestamp: "' . $timestamp . '"');
|
||||
|
||||
// Parsing dengan DateTime native PHP untuk lebih robust
|
||||
try {
|
||||
// Pattern untuk format d/m/Y H:i:s
|
||||
if (preg_match('/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2}):(\d{1,2})$/', $timestamp, $matches)) {
|
||||
$day = (int) $matches[1];
|
||||
$month = (int) $matches[2];
|
||||
$year = (int) $matches[3];
|
||||
$hour = (int) $matches[4];
|
||||
$minute = (int) $matches[5];
|
||||
$second = (int) $matches[6];
|
||||
|
||||
// Validasi nilai
|
||||
if ($day >= 1 && $day <= 31 && $month >= 1 && $month <= 12 && $year >= 1900 && $year <= 2100 &&
|
||||
$hour >= 0 && $hour <= 23 && $minute >= 0 && $minute <= 59 && $second >= 0 && $second <= 59) {
|
||||
|
||||
// Buat DateTime object langsung
|
||||
$dateTime = new \DateTime();
|
||||
$dateTime->setDate($year, $month, $day);
|
||||
$dateTime->setTime($hour, $minute, $second);
|
||||
|
||||
$result = $dateTime->format('Y-m-d H:i:s');
|
||||
Log::info('Berhasil parsing dengan DateTime: ' . $timestamp . ' -> ' . $result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Pattern untuk format d/m/Y tanpa waktu
|
||||
if (preg_match('/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/', $timestamp, $matches)) {
|
||||
$day = (int) $matches[1];
|
||||
$month = (int) $matches[2];
|
||||
$year = (int) $matches[3];
|
||||
|
||||
// Validasi nilai
|
||||
if ($day >= 1 && $day <= 31 && $month >= 1 && $month <= 12 && $year >= 1900 && $year <= 2100) {
|
||||
|
||||
// Buat DateTime object langsung
|
||||
$dateTime = new \DateTime();
|
||||
$dateTime->setDate($year, $month, $day);
|
||||
$dateTime->setTime(0, 0, 0);
|
||||
|
||||
$result = $dateTime->format('Y-m-d H:i:s');
|
||||
Log::info('Berhasil parsing tanpa waktu dengan DateTime: ' . $timestamp . ' -> ' . $result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal parsing dengan DateTime: ' . $timestamp . '. Error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// Fallback ke format Carbon standar untuk format lainnya
|
||||
$formats = [
|
||||
'Y-m-d H:i:s',
|
||||
'Y-m-d',
|
||||
'd-m-Y H:i:s',
|
||||
'd-m-Y',
|
||||
'j-n-Y H:i:s',
|
||||
'j-n-Y',
|
||||
$data = json_decode(json_encode($notifikasi->data));
|
||||
$message = $data->message;
|
||||
$data = $data->data;
|
||||
$notifikasi = [
|
||||
'title' => 'Permohonan : ' . $data->nomor_registrasi,
|
||||
'message' => $message,
|
||||
];
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$carbon = \Carbon\Carbon::createFromFormat($format, $timestamp);
|
||||
|
||||
if ($carbon && $carbon->format($format) === $timestamp) {
|
||||
// Jika format tidak mengandung waktu, set ke awal hari
|
||||
if (!str_contains($format, 'H:i:s')) {
|
||||
$carbon = $carbon->startOfDay();
|
||||
}
|
||||
Log::info('Berhasil parsing dengan format ' . $format . ': ' . $timestamp . ' -> ' . $carbon->toDateTimeString());
|
||||
return $carbon->toDateTimeString();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Lanjut ke format berikutnya
|
||||
continue;
|
||||
}
|
||||
return $notifikasi;
|
||||
}
|
||||
|
||||
Log::error('Tidak dapat memparsing timestamp dengan format apapun: "' . $timestamp . '"');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,6 @@ class ActivityController extends Controller
|
||||
$query = Permohonan::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
$query = $query->orderBy('nomor_registrasi', 'desc');
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
@@ -325,9 +324,7 @@ class ActivityController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Apply sorting if provided
|
||||
// Default sorting if no sort provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
@@ -336,13 +333,20 @@ class ActivityController extends Controller
|
||||
$query->orderBy('nomor_registrasi', 'asc');
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
// Get total count of records before pagination
|
||||
$totalRecords = $query->count();
|
||||
$size = $request->get('size', 10);
|
||||
if ($size == 0) {
|
||||
$size = 10;
|
||||
|
||||
// Pagination
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = (int) $request->get('page', 1);
|
||||
$size = (int) $request->get('size', 10);
|
||||
$offset = ($page - 1) * $size;
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get filtered count
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Filter by region if user is senior-officer
|
||||
if ($regionId) {
|
||||
$query->whereHas('region', function ($q) use ($regionId) {
|
||||
@@ -357,36 +361,37 @@ class ActivityController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$totalRecords = $query->count();
|
||||
|
||||
|
||||
// Apply pagination if provided
|
||||
// Pagination
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$page = (int) $request->get('page', 1);
|
||||
$size = (int) $request->get('size', 10);
|
||||
$offset = ($page - 1) * $size;
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
// Get filtered count
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get data with necessary relationships
|
||||
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'dokumenjaminan','nilaiPlafond'])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $size);
|
||||
// Calculate total pages
|
||||
$pageCount = ceil($totalRecords / $request->get('size', 10));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = max(1, $request->get('page', 1));
|
||||
|
||||
// Return the response data as a JSON object
|
||||
|
||||
|
||||
// Calculate total pages
|
||||
$pageCount = ceil($totalRecords / $request->get('size', 10));
|
||||
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'page' => $request->get('page', 1),
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Lpj\Http\Requests\BankDataRequest;
|
||||
use Modules\Lpj\Models\BankData;
|
||||
@@ -92,7 +92,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data_pembanding->data_pembanding)) {
|
||||
foreach ($data_pembanding->data_pembanding as $dataPembanding) {
|
||||
if (!isset($dataPembanding->kordinat_lat) || !isset($dataPembanding->kordinat_lng)) {
|
||||
continue;
|
||||
}
|
||||
$lat = $dataPembanding->kordinat_lat;
|
||||
$lng = $dataPembanding->kordinat_lng;
|
||||
|
||||
@@ -123,7 +127,7 @@
|
||||
'hak_properti' => $dataPembanding->hak_properti,
|
||||
'jenis_aset' => $dataPembanding->jenis_aset,
|
||||
'foto_objek' => $dataPembanding->foto_objek,
|
||||
'tanggal' => $dataPembanding->tanggal,
|
||||
'tanggal' => $dataPembanding->tanggal ?? null,
|
||||
'kategori' => 'data_pembanding',
|
||||
];
|
||||
|
||||
@@ -143,6 +147,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('lpj::bank-data.index', compact('provinces', 'jenisJaminan'));
|
||||
}
|
||||
@@ -246,7 +251,19 @@
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
|
||||
// Handle special cases for computed fields
|
||||
if ($column === 'location') {
|
||||
$query->orderBy('kordinat_lat', $order)
|
||||
->orderBy('kordinat_lng', $order);
|
||||
}
|
||||
// Map frontend column names to database columns
|
||||
else if ($column === 'sumber') {
|
||||
$column = 'kategori'; // Sort by kategori when sumber is requested
|
||||
$query->orderBy($column, $order);
|
||||
} else {
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
@@ -272,7 +289,7 @@
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'jenis_aset' => $item->jenis_aset,
|
||||
'tanggal' => $item->tanggal ? $item->tanggal->format('d-m-Y') : '-',
|
||||
'tanggal' => isset($item->tanggal) && $item->tanggal ? $item->tanggal->format('d-m-Y') : '-',
|
||||
'tahun' => $item->tahun,
|
||||
'luas_tanah' => $item->luas_tanah,
|
||||
'luas_bangunan' => $item->luas_bangunan,
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\CategoryDaftarPustaka;
|
||||
use Modules\Lpj\Http\Requests\CategoryDaftarPustakaRequest;
|
||||
|
||||
class CategoryDaftarPustakaController extends Controller
|
||||
{
|
||||
public $user;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::category-daftar-pustaka.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('lpj::category-daftar-pustaka.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CategoryDaftarPustakaRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
if ($validated) {
|
||||
try {
|
||||
CategoryDaftarPustaka::create($validated);
|
||||
return redirect()->route('category-daftar-pustaka.index')->with('success', 'Data Berhasil Disimpan');
|
||||
} catch (\Throwable $th) {
|
||||
return redirect()->route('category-daftar-pustaka.index')->with('error', $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$category = CategoryDaftarPustaka::where('id', $id)->first();
|
||||
return view('lpj::category-daftar-pustaka.show', compact('category'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('lpj::category-daftar-pustaka.create', ['category' => CategoryDaftarPustaka::where('id', $id)->first()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(CategoryDaftarPustakaRequest $request, $id)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
if ($validated) {
|
||||
try {
|
||||
CategoryDaftarPustaka::where('id', $id)->update($validated);
|
||||
return redirect()->route('category-daftar-pustaka.index')->with('success', 'Data Berhasil Disimpan');
|
||||
} catch (\Throwable $th) {
|
||||
return redirect()->route('category-daftar-pustaka.index')->with('error', $th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
CategoryDaftarPustaka::where('id', $id)->delete();
|
||||
return response()->json(['success' => true, 'message' => 'Data Berhasil Dihapus']);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json(['success' => false, 'message' => $th->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('jenis_aset.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = CategoryDaftarPustaka::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('code', 'LIKE', "%$search%");
|
||||
$q->orWhere('name', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = 0 + 1;
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\CategoryDaftarPustaka;
|
||||
use Modules\Lpj\Services\DaftarPustakaService;
|
||||
use Modules\Lpj\Http\Requests\DaftarPustakaRequest;
|
||||
|
||||
class DaftarPustakaController extends Controller
|
||||
{
|
||||
private $daftarPustaka;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->daftarPustaka = app(DaftarPustakaService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$categories = CategoryDaftarPustaka::all();
|
||||
$daftar_pustaka = $this->daftarPustaka->getAllDaftarPustaka($request);
|
||||
|
||||
return view('lpj::daftar-pustaka.index', [
|
||||
'categories' => $categories,
|
||||
'daftar_pustaka' => $daftar_pustaka,
|
||||
'page' => $daftar_pustaka->currentPage(),
|
||||
'pageCount' => $daftar_pustaka->lastPage(),
|
||||
'limit' => $daftar_pustaka->perPage(),
|
||||
'total' => $daftar_pustaka->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$categories = CategoryDaftarPustaka::all();
|
||||
// dd($categories);
|
||||
return view('lpj::daftar-pustaka.create', compact('categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(DaftarPustakaRequest $request)
|
||||
{
|
||||
|
||||
$validate = $request->validated();
|
||||
// dd($validate);
|
||||
$file = $request->file('attachment');
|
||||
if ($validate) {
|
||||
try {
|
||||
// Save to database
|
||||
$this->daftarPustaka->storeDaftarPustaka($validate, $file);
|
||||
return redirect()
|
||||
->route('daftar-pustaka.index')
|
||||
->with('success', 'Daftar Pustaka created successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect()
|
||||
->route('daftar-pustaka.create')
|
||||
->with('error', 'Failed to create daftar pustaka');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$daftarPustaka = $this->daftarPustaka->getDaftarPustakaById($id);
|
||||
$categories = CategoryDaftarPustaka::all();
|
||||
|
||||
return view('lpj::daftar-pustaka.show', compact('daftarPustaka', 'categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$daftarPustaka = $this->daftarPustaka->getDaftarPustakaById($id);
|
||||
$categories = CategoryDaftarPustaka::all();
|
||||
return view('lpj::daftar-pustaka.create', compact('daftarPustaka', 'categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(DaftarPustakaRequest $request, $id)
|
||||
{
|
||||
$validate = $request->validated();
|
||||
if ($validate) {
|
||||
try {
|
||||
// Save to database
|
||||
$file = $request->file('attachment');
|
||||
$this->daftarPustaka->updateDaftarPustaka($validate, $file, $id);
|
||||
return redirect()
|
||||
->route('daftar-pustaka.index')
|
||||
->with('success', 'Daftar Pustaka updated successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect()
|
||||
->route('daftar-pustaka.create')
|
||||
->with('error', 'Failed to update daftar pustaka');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$this->daftarPustaka->deleteDaftarPustaka($id);
|
||||
return response()->json(['success' => true, 'message' => 'Daftar Pustaka deleted successfully']);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['success' => false, 'message' => 'Failed to delete daftar pustaka']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Services\DashboardService;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public $dashboardService;
|
||||
public function __construct(DashboardService $dashboardService)
|
||||
{
|
||||
$this->dashboardService = $dashboardService;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// nilai default
|
||||
$start_date = $request->input('start_date', now()->startOfYear()->format('Y-m-d'));
|
||||
$end_date = $request->input('end_date', now()->format('Y-m-d'));
|
||||
|
||||
$validate = $request->validate([
|
||||
'start_date' => 'nullable|date_format:Y-m-d',
|
||||
'end_date' => 'nullable|date_format:Y-m-d',
|
||||
]);
|
||||
|
||||
$dashboard = $this->dashboardService->getDashboardData($start_date, $end_date);
|
||||
|
||||
// dd($dashboard);
|
||||
return view('lpj::dashboard.index', compact('dashboard'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -406,9 +406,7 @@
|
||||
|
||||
|
||||
// Remove values from $legalitasJaminan that are in $currentLegalitasJaminan
|
||||
$legalitasJaminan = is_array($legalitasJaminan)
|
||||
? array_diff($legalitasJaminan, $currentLegalitasJaminan->pluck('code')->toArray())
|
||||
: [];
|
||||
$legalitasJaminan = array_diff($legalitasJaminan, $currentLegalitasJaminan->pluck('code')->toArray());
|
||||
|
||||
$legalitas = JenisLegalitasJaminan::whereIn('code', $legalitasJaminan)->get();
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LaporanBiayaInternalExternalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function showLaporanBiayaInternal()
|
||||
{
|
||||
return view('lpj::laporan-biaya.internal');
|
||||
}
|
||||
|
||||
public function showLaporanBiayaExternal()
|
||||
{
|
||||
return view('lpj::laporan-biaya.external');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,9 +75,11 @@ class LaporanController extends Controller
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query()
|
||||
->whereIn('status',['proses-laporan','done', 'paparan', 'proses-paparan']);
|
||||
|
||||
$query = Permohonan::query()->whereIn('status',['proses-laporan','done', 'paparan', 'proses-paparan'])->whereNotNull('approval_so_at')->whereNotNull('approval_eo_at')->where(function ($q) {
|
||||
$q->whereIn('nilai_plafond_id', [1,4])
|
||||
->whereNotNull('approval_dd_at')
|
||||
->orWhereIn('nilai_plafond_id', [2,3]);
|
||||
});
|
||||
|
||||
$query = $query->orderBy('nomor_registrasi', 'desc');
|
||||
// Apply search filter if provided
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Services\LaporanDebitureService;
|
||||
|
||||
class LaporanDebitureController extends Controller
|
||||
{
|
||||
private $laporanDebitureService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->laporanDebitureService = app(LaporanDebitureService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$debiture = Debiture::all();
|
||||
return view('lpj::laporan-debiture.index', compact('debiture'));
|
||||
}
|
||||
|
||||
|
||||
public function dataTableForDebiture(Request $request)
|
||||
{
|
||||
return $this->laporanDebitureService->dataForDatatables($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,6 @@ use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\LaporanHasilPenilaianJaminanInternalExternalExport;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanHasilPenilaianJaminanInternalExternalController extends Controller
|
||||
{
|
||||
@@ -61,7 +60,6 @@ class LaporanHasilPenilaianJaminanInternalExternalController extends Controller
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search->search) . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->search . '%');
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Services\LaporanMonitoringSoService;
|
||||
|
||||
class LaporanMonitoringSoController extends Controller
|
||||
{
|
||||
|
||||
private $laporanMonitoringSoService;
|
||||
|
||||
public function __construct(LaporanMonitoringSoService $laporanMonitoringSoService)
|
||||
{
|
||||
$this->laporanMonitoringSoService = $laporanMonitoringSoService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = auth()->user()->load('roles');
|
||||
$result = $this->laporanMonitoringSoService->progresPengerjaanLaporan($user);
|
||||
return view('lpj::laporan-monitoring.index', compact('result'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show details data.
|
||||
* @return Response
|
||||
*/
|
||||
|
||||
public function show($id){
|
||||
return view('lpj::laporan-monitoring.show', compact('id'));
|
||||
}
|
||||
|
||||
|
||||
public function dataForDatatablePenilai(Request $request, $id){
|
||||
return $this->laporanMonitoringSoService->showDetailsPermohonan($request, $id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\TeamsUsers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Models\StatusPermohonan;
|
||||
use Modules\Lpj\Exports\LaporanPenilaiJaminanExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Services\PreviewLaporanService;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
|
||||
class LaporanPenilaiJaminanController extends Controller
|
||||
{
|
||||
@@ -20,31 +17,59 @@ class LaporanPenilaiJaminanController extends Controller
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
protected $previewLaporanService;
|
||||
|
||||
public function __construct(PreviewLaporanService $previewLaporanService)
|
||||
{
|
||||
$this->previewLaporanService = $previewLaporanService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$status_permohonan = StatusPermohonan::all();
|
||||
return view('lpj::laporan-penilai-jaminan.index', compact('status_permohonan'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('lpj::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($permohonan_id, $dokumen_id, $jaminan_id)
|
||||
public function show($id)
|
||||
{
|
||||
$back = route('laporan-penilai-jaminan.index');
|
||||
return $this->previewLaporanService->previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back);
|
||||
return view('lpj::laporan-penilai-jaminan.show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('lpj::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
@@ -69,104 +94,91 @@ class LaporanPenilaiJaminanController extends Controller
|
||||
// dd($startDate);
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
$query = $query->where('status', 'done')->orderBy('tanggal_permohonan', 'desc');
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
|
||||
if (!empty($search->start_date) || !empty($search->end_date)) {
|
||||
$startDate = $search->start_date ?? '1900-01-01';
|
||||
$endDate = $search->end_date ?? now()->toDateString();
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
});
|
||||
|
||||
// OR check if has penawaran with date in range
|
||||
$q->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (isset($search->branch_id) && !empty($search->branch_id)) {
|
||||
$query->where('branch_id', $search->branch_id);
|
||||
}
|
||||
|
||||
if (isset($search->laporan) && is_array($search->laporan) && !empty($search->laporan)) {
|
||||
foreach ($search->laporan as $type) {
|
||||
$query->whereHas('penilai', function ($q) use ($type) {
|
||||
$q->where('type_penilai', 'LIKE', '%' . $type . '%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// dd($search->search);
|
||||
|
||||
if (isset($search->search)) {
|
||||
$search = $request->get('search');
|
||||
$paramsSearch = json_decode($search);
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search->search) . '%');
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%')
|
||||
->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%')
|
||||
->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%')
|
||||
->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%')
|
||||
->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->search . '%');
|
||||
if (!empty($paramsSearch->tanggal_awal) && !empty($paramsSearch->tanggal_akhir)) {
|
||||
$q->whereBetween('tanggal_permohonan', [$paramsSearch->tanggal_awal, $paramsSearch->tanggal_akhir]);
|
||||
}
|
||||
|
||||
|
||||
$statusKeywords = explode(',', $search);
|
||||
foreach ($statusKeywords as $keyword) {
|
||||
$q->orWhereRelation('penilai', 'type_penilai', 'LIKE', '%' . trim($keyword) . '%');
|
||||
}
|
||||
});
|
||||
}
|
||||
$query->where('status', 'done');
|
||||
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
|
||||
// Default sorting if no sort provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
} else {
|
||||
$query->orderBy('nomor_registrasi', 'asc');
|
||||
}
|
||||
|
||||
|
||||
// Get the total count of records
|
||||
// Get total count of records before pagination
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
// Pagination
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$page = (int) $request->get('page', 1);
|
||||
$size = (int) $request->get('size', 10);
|
||||
$offset = ($page - 1) * $size;
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
// Get filtered count
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
|
||||
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Pagination
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = (int) $request->get('page', 1);
|
||||
$size = (int) $request->get('size', 10);
|
||||
$offset = ($page - 1) * $size;
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get filtered count
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get data with necessary relationships
|
||||
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'dokumenjaminan.jenisJaminan','nilaiPlafond', 'penilai', 'dokumenjaminan.inspeksi'])->get();
|
||||
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'dokumenjaminan.jenisJaminan', 'nilaiPlafond', 'penilai'])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $size);
|
||||
// Calculate total pages
|
||||
$pageCount = ceil($totalRecords / $request->get('size', 10));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = max(1, $request->get('page', 1));
|
||||
|
||||
// Return the response data as a JSON object
|
||||
|
||||
|
||||
// Calculate total pages
|
||||
$pageCount = ceil($totalRecords / $request->get('size', 10));
|
||||
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'page' => $request->get('page', 1),
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
@@ -174,53 +186,15 @@ class LaporanPenilaiJaminanController extends Controller
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
|
||||
// Validate the date format
|
||||
if (isset($startDate) && isset($endDate)) {
|
||||
$startDate = date('Y-m-d', strtotime($startDate));
|
||||
$endDate = date('Y-m-d', strtotime($endDate));
|
||||
|
||||
if ($startDate > $endDate) {
|
||||
return redirect()->back()->with('error', 'Tanggal awal tidak boleh lebih kecil dari tanggal akhir');
|
||||
}
|
||||
}
|
||||
// name the file
|
||||
$filename = $this->createNameLaporan($request);
|
||||
$tanggalAwal = $request->input('tanggal_awal');
|
||||
$tanggalAkhir = $request->input('tanggal_akhir');
|
||||
$status = $request->input('status');
|
||||
$selectedIds = $request->input('selected_ids');
|
||||
|
||||
$filename = 'laporan_penilai_jaminan_' . date('YmdHis') . '.xlsx';
|
||||
return Excel::download(
|
||||
new LaporanPenilaiJaminanExport($request),
|
||||
new LaporanPenilaiJaminanExport($tanggalAwal, $tanggalAkhir, $status, $selectedIds),
|
||||
$filename
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function createNameLaporan($request)
|
||||
{
|
||||
$startDate = $request->start_date ?? null;
|
||||
$endDate = $request->end_date ?? null;
|
||||
$branchId = $request->branch_id ?? null;
|
||||
$laporan = $request->laporan ?? null;
|
||||
|
||||
// Initialize filename parts
|
||||
$parts = ['Laporan Penilai Jaminan'];
|
||||
if ($startDate && $endDate) {
|
||||
$parts[] = "{$startDate}_{$endDate}";
|
||||
}
|
||||
if ($laporan) {
|
||||
$parts[] = $laporan;
|
||||
}
|
||||
if ($branchId) {
|
||||
$parts[] = $this->getBranchId($branchId);
|
||||
}
|
||||
// Return concatenated filename with extension
|
||||
return implode('_', $parts) . '.xlsx';
|
||||
}
|
||||
|
||||
public function getBranchId($branchId)
|
||||
{
|
||||
$branchesName = Branch::find($branchId)->name ?? null;
|
||||
return $branchesName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Exports\LaporanPenilaianJaminanExport;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\PenawaranTender;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LaporanPenilaianJaminanController extends Controller
|
||||
{
|
||||
@@ -37,19 +34,11 @@ class LaporanPenilaianJaminanController extends Controller
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
|
||||
|
||||
if (!empty($search->start_date) || !empty($search->end_date)) {
|
||||
$startDate = $search->start_date ?? '1900-01-01';
|
||||
$endDate = $search->end_date ?? now()->toDateString();
|
||||
|
||||
$query->where(function ($q) use ($startDate, $endDate) {
|
||||
$q->whereHas('penilaian', function ($q2) use ($startDate, $endDate) {
|
||||
$q2->whereBetween('tanggal_kunjungan', [$startDate, $endDate]);
|
||||
})
|
||||
->orWhereHas('penawaran', function ($q3) use ($startDate, $endDate) {
|
||||
$q3->whereBetween('tanggal_penilaian_sebelumnya', [$startDate, $endDate]);
|
||||
});
|
||||
});
|
||||
if (isset($search->start_date) || isset($search->end_date)) {
|
||||
$query->whereBetween('tanggal_permohonan', [
|
||||
$search->start_date ?? '1900-01-01',
|
||||
$search->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
// Filter by branch if provided
|
||||
@@ -71,8 +60,6 @@ class LaporanPenilaianJaminanController extends Controller
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('debiture', DB::raw('LOWER(name)'), 'LIKE', '%' . strtolower($search->search) . '%');
|
||||
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->search . '%');
|
||||
@@ -169,12 +156,6 @@ class LaporanPenilaianJaminanController extends Controller
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$startDate = $request->start_date;
|
||||
$endDate = $request->end_date;
|
||||
// name of the file
|
||||
$fileName = 'laporan_penilaian_jaminan_' . $startDate . '_' . $endDate . '.xlsx';
|
||||
return Excel::download(new LaporanPenilaianJaminanExport($request), $fileName);
|
||||
return Excel::download(new LaporanPenilaianJaminanExport($request), 'laporan_penilaian_jaminan.xlsx');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Services\LaporanSLAPenilaiService;
|
||||
|
||||
class LaporanSLAPenilaiController extends Controller
|
||||
{
|
||||
private $laporanSLAPenilaiService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->laporanSLAPenilaiService = app(LaporanSLAPenilaiService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::laporan-sla-penilai.index');
|
||||
}
|
||||
|
||||
public function dataForDatatableSLaPenilai(Request $request)
|
||||
{
|
||||
return $this->laporanSLAPenilaiService->dataForDatatables($request);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\LaporanUserLimitExport;
|
||||
use Modules\Lpj\Services\LaporanUserService;
|
||||
|
||||
class LaporanUserController extends Controller
|
||||
{
|
||||
|
||||
|
||||
private $laporanUserService;
|
||||
|
||||
public function __construct(LaporanUserService $laporanUserService)
|
||||
{
|
||||
$this->laporanUserService = $laporanUserService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// $user = $this->laporanUserService->getUserPemohon();
|
||||
return view('lpj::laporan-user.index');
|
||||
}
|
||||
|
||||
public function searchUserPemohon(Request $request)
|
||||
{
|
||||
$search = $request->get('search');
|
||||
$user = $this->laporanUserService->getUserPemohon($search);
|
||||
return response()->json($user);
|
||||
}
|
||||
|
||||
public function dataTableForUserPemohon(Request $request)
|
||||
{
|
||||
return $this->laporanUserService->dataForDatatables($request);
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$startDate = $request->start_date;
|
||||
$endDate = $request->end_date;
|
||||
// name of the file
|
||||
$fileName = 'laporan_user_limit' . $startDate . '_' . $endDate . '.xlsx';
|
||||
return Excel::download(new LaporanUserLimitExport($request), $fileName);
|
||||
}
|
||||
}
|
||||
@@ -19,20 +19,9 @@
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return redirect()->route('noc.pembayaran.index');
|
||||
}
|
||||
|
||||
public function pembayaran()
|
||||
{
|
||||
$persetujuanPenawarans = PersetujuanPenawaran::all();
|
||||
return view('lpj::noc.pembayaran', compact('persetujuanPenawarans'));
|
||||
}
|
||||
|
||||
public function penyelesaian()
|
||||
{
|
||||
$persetujuanPenawarans = PersetujuanPenawaran::all();
|
||||
return view('lpj::noc.penyelesaian', compact('persetujuanPenawarans'));
|
||||
return view('lpj::noc.index', compact('persetujuanPenawarans'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +69,7 @@
|
||||
}
|
||||
$noc->save();
|
||||
|
||||
/* Update the status of the related permohonan to 'spk'
|
||||
// Update the status of the related permohonan to 'spk'
|
||||
$permohonan = Permohonan::find(request()->get('permohonan_id'));
|
||||
if ($permohonan) {
|
||||
$permohonan->status_bayar = request()->get('status_pembayar');
|
||||
@@ -99,7 +88,7 @@
|
||||
]);
|
||||
}
|
||||
// andy add, update status penawaran.status='spk'
|
||||
}*/
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('noc.index')->with('success', 'NOC berhasil disimpan.');
|
||||
@@ -142,7 +131,6 @@
|
||||
|
||||
$noc = Noc::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $validated['permohonan_id'],
|
||||
'permohonan_id' => $validated['permohonan_id'],
|
||||
'persetujuan_penawaran_id' => $validated['persetujuan_penawaran_id'],
|
||||
],
|
||||
@@ -175,7 +163,9 @@
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Noc $noc) {
|
||||
public function show(Request $request) {
|
||||
$noc = Noc::find($request->get('id'));
|
||||
|
||||
return view('lpj::noc.memo', compact('noc'));
|
||||
}
|
||||
|
||||
@@ -200,12 +190,6 @@
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
// Redirect to pembayaran datatables by default
|
||||
return $this->dataForDatatablesPembayaran($request);
|
||||
}
|
||||
|
||||
public function dataForDatatablesPembayaran(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('noc.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view persetujuan penawaran.');
|
||||
@@ -214,97 +198,6 @@
|
||||
// Retrieve data from the database
|
||||
$query = PersetujuanPenawaran::query();
|
||||
|
||||
// Filter for pembayaran (where memo_penyelesaian is null)
|
||||
$query->whereDoesntHave('noc', function($q) {
|
||||
$q->whereNotNull('memo_penyelesaian');
|
||||
});
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->orWhereRelation('penawaran', 'nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->get();
|
||||
|
||||
$data = $data->map(function ($persetujuanPenawaran) {
|
||||
return [
|
||||
'id' => $persetujuanPenawaran->id,
|
||||
'nomor_registrasi' => $persetujuanPenawaran->permohonan->nomor_registrasi ?? $persetujuanPenawaran->penawaran->nomor_registrasi,
|
||||
'nama_debitur' => $persetujuanPenawaran->permohonan->debiture->name ?? $persetujuanPenawaran->penawaran->permohonan->debiture->name,
|
||||
'cabang' => $persetujuanPenawaran->permohonan->branch->name ?? $persetujuanPenawaran->penawaran->permohonan->branch->name,
|
||||
'tanggal_pembayaran' => dateFormat(
|
||||
$persetujuanPenawaran->noc->tanggal_pembayaran ?? $persetujuanPenawaran->noc?->created_at,
|
||||
true,
|
||||
),
|
||||
'nominal_bayar' => currencyFormat($persetujuanPenawaran->nominal_bayar ?? 0,
|
||||
),
|
||||
'nominal_diterima' => currencyFormat(
|
||||
$persetujuanPenawaran->noc->nominal_bayar ?? 0,
|
||||
),
|
||||
'bukti_ksl' => $persetujuanPenawaran->noc->bukti_ksl ?? $persetujuanPenawaran->bukti_ksl ?? null,
|
||||
'bukti_bayar' => $persetujuanPenawaran->bukti_bayar ?? null,
|
||||
'updated_at' => dateFormat($persetujuanPenawaran->updated_at, true),
|
||||
];
|
||||
})->sortBy('updated_at', 1);
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function dataForDatatablesPenyelesaian(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('noc.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view persetujuan penawaran.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = PersetujuanPenawaran::query();
|
||||
|
||||
// Filter for penyelesaian (where memo_penyelesaian is not null)
|
||||
$query->whereHas('noc', function($q) {
|
||||
$q->whereNotNull('memo_penyelesaian');
|
||||
});
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
class PembatalanController extends Controller
|
||||
{
|
||||
public $user;
|
||||
protected $historyService;
|
||||
|
||||
public function __construct(PermohonanHistoryService $historyService)
|
||||
@@ -36,23 +35,27 @@
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::pembatalan.index');
|
||||
$user = auth()->user();
|
||||
return view('lpj::pembatalan.index', compact('user'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture', 'permohonan.branch'])->find($id);
|
||||
|
||||
return view(
|
||||
'lpj::pembatalan.form',
|
||||
compact(
|
||||
'pembatalan'
|
||||
'pembatalan',
|
||||
'user'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
||||
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
||||
$beforeRequest = $permohonan->toArray();
|
||||
@@ -62,7 +65,7 @@
|
||||
if ($request->status == 'approved') {
|
||||
$pembatalan->status = 'approved';
|
||||
$pembatalan->authorized_at = now();
|
||||
$pembatalan->authorized_by = auth()->user()->id;
|
||||
$pembatalan->authorized_by = $user->id;
|
||||
$pembatalan->authorized_status = 1;
|
||||
$pembatalan->save();
|
||||
|
||||
@@ -71,7 +74,7 @@
|
||||
} else {
|
||||
$pembatalan->status = 'rejected';
|
||||
$pembatalan->authorized_at = now();
|
||||
$pembatalan->authorized_by = auth()->user()->id;
|
||||
$pembatalan->authorized_by = $user->id;
|
||||
$pembatalan->authorized_status = 3;
|
||||
$pembatalan->save();
|
||||
}
|
||||
@@ -86,12 +89,13 @@
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
||||
$user = auth()->user();
|
||||
if (is_null($user) || !$user->can('debitur.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = PermohonanPembatalan::query();
|
||||
$query = PermohonanPembatalan::query()->with(['permohonan']);
|
||||
$query = $query->orderBy('created_at', 'desc');
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
@@ -108,8 +112,11 @@
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
// Only allow sorting by existing columns
|
||||
if (in_array($column, ['created_at', 'status', 'alasan_pembatalan'])) {
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
@@ -210,9 +210,14 @@ class PembayaranController extends Controller
|
||||
}
|
||||
|
||||
if ($permohonan->jenis_penilaian_id == 2) {
|
||||
if ($request->type === 'revisi') {
|
||||
$data['status'] = 'revisi-pembayaran';
|
||||
$data['status_bayar'] = 'belum_bayar';
|
||||
} else {
|
||||
$data['status_bayar'] = 'sudah_bayar';
|
||||
$data['status'] = 'spk';
|
||||
}
|
||||
}
|
||||
|
||||
if ($permohonan->jenis_penilaian_id == 1) {
|
||||
unset(
|
||||
@@ -224,12 +229,11 @@ class PembayaranController extends Controller
|
||||
$data['approval_dd_at'],
|
||||
$data['keterangan']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$permohonan->update($data);
|
||||
|
||||
if ($permohonan->jenis_penilaian_id == 2) {
|
||||
if ($permohonan->jenis_penilaian_id == 2 && $permohonan->status_bayar == 'sudah_bayar') {
|
||||
PenawaranTender::where('nomor_registrasi', $permohonan->nomor_registrasi)->update([
|
||||
'status' => 'spk',
|
||||
'updated_by' => Auth::id(),
|
||||
|
||||
@@ -26,21 +26,18 @@ use Modules\Lpj\Http\Requests\FormSurveyorRequest;
|
||||
use Modules\Lpj\Models\Authorization;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Services\SaveFormInspesksiService;
|
||||
use Modules\Lpj\Services\PreviewLaporanService;
|
||||
|
||||
class PenilaiController extends Controller
|
||||
{
|
||||
public $user;
|
||||
protected $surveyorController;
|
||||
protected $inspeksiService;
|
||||
protected $previewLaporanService;
|
||||
|
||||
|
||||
public function __construct(SurveyorController $surveyorController, SaveFormInspesksiService $inspeksiService, PreviewLaporanService $previewLaporanService)
|
||||
public function __construct(SurveyorController $surveyorController, SaveFormInspesksiService $inspeksiService)
|
||||
{
|
||||
$this->surveyorController = $surveyorController;
|
||||
$this->inspeksiService = $inspeksiService;
|
||||
$this->previewLaporanService = $previewLaporanService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,11 +152,6 @@ class PenilaiController extends Controller
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId($id, $documentId, $jaminanId);
|
||||
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
return redirect()->back()->with('error', 'Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
$noLpSederhana = $this->generateNoLaporan($permohonan, $documentId, 'lpj');
|
||||
|
||||
@@ -226,11 +218,6 @@ class PenilaiController extends Controller
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
||||
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
return redirect()->back()->with('error', 'Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$nomorLaporan = $this->generateNoLaporan($permohonan, $documentId, 'resume');
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
$noLpresume = $this->generateNoLaporan($permohonan, $documentId, 'resume');
|
||||
@@ -266,9 +253,6 @@ class PenilaiController extends Controller
|
||||
|
||||
$data = $this->getDataPermohonanWithPenilaiAndInspeksi($req['permohonanId'], $req['documentId'], $req['jaminanId']);
|
||||
$permohonan = $data['permohonan'];
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
return redirect()->back()->with('error', 'Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$nomorLaporan = $this->generateNoLaporan($permohonan, $req['documentId'], 'memo');
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $req['permohonanId'])->where('dokument_id', $req['documentId'])->first();
|
||||
@@ -408,11 +392,6 @@ class PenilaiController extends Controller
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
$provinces = Province::all();
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
||||
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
return redirect()->back()->with('error', 'Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$nomorLaporan = $this->generateNoLaporan($permohonan, $documentId, 'rap');
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
@@ -491,9 +470,6 @@ class PenilaiController extends Controller
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
$provinces = Province::all();
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
return redirect()->back()->with('error', 'Masih dalam proses laporan');
|
||||
}
|
||||
$nomorLaporan = $this->generateNoLaporan($permohonan, $documentId, 'call-report');
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
@@ -551,7 +527,13 @@ class PenilaiController extends Controller
|
||||
return view('lpj::penilai.components.call-report', compact('permohonan', 'basicData', 'nomorLaporan', 'forminspeksi', 'cities', 'districts', 'villages', 'cekAlamat', 'callReport'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
@@ -697,7 +679,6 @@ class PenilaiController extends Controller
|
||||
'lokasi_lengkap' => $data->lokasi_lengkap ?? '',
|
||||
];
|
||||
|
||||
if(isset($dataPembanding)){
|
||||
// Extract data pembanding
|
||||
if (isset($dataPembanding['data_pembanding'])) {
|
||||
foreach ($dataPembanding['data_pembanding'] as $index => $pembanding) {
|
||||
@@ -710,7 +691,6 @@ class PenilaiController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now create the export
|
||||
// return response()->json([ 'data' => $fotoForm]);
|
||||
@@ -1124,7 +1104,8 @@ class PenilaiController extends Controller
|
||||
$penilai = Penilai::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $request->permohonanId,
|
||||
'dokument_id' => $request->input('dokument_id'),
|
||||
'dokument_id' => $request->documentId,
|
||||
|
||||
],
|
||||
[
|
||||
'lpj' => json_encode($data),
|
||||
@@ -1151,9 +1132,20 @@ class PenilaiController extends Controller
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$formRequest = new FormSurveyorRequest();
|
||||
$formRequest->setContainer(app());
|
||||
$formRequest->initialize(
|
||||
$request->all(),
|
||||
$request->query->all(),
|
||||
$request->attributes->all(),
|
||||
$request->cookies->all(),
|
||||
$request->files->all(),
|
||||
$request->server->all(),
|
||||
$request->getContent()
|
||||
);
|
||||
|
||||
$validatedData = $request->all();
|
||||
$result = $this->inspeksiService->storeInspeksi($validatedData, $request->input('type'), $request);
|
||||
$validated = $formRequest->validateResolved();
|
||||
$result = $this->surveyorController->store($formRequest);
|
||||
|
||||
$data = [
|
||||
'kepada' => $request->input('kepada'),
|
||||
@@ -1276,13 +1268,132 @@ class PenilaiController extends Controller
|
||||
|
||||
|
||||
|
||||
public function print_out_laporan($permohonan_id, $document_id, $jaminan_id)
|
||||
public function print_out(Request $request)
|
||||
{
|
||||
// jika tidak ada id kembalikan ke halaman sebelumnya
|
||||
if (!$permohonan_id || !$document_id || !$jaminan_id) {
|
||||
return redirect()->back()->with('error', 'Laporan tidak valid');
|
||||
$documentId = $request->query('documentId');
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
$permohonanId = $request->query('permohonanId');
|
||||
$statusLpj = $request->query('statusLpj');
|
||||
$tipeLaporan = $request->query('type');
|
||||
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId(
|
||||
$permohonanId,
|
||||
$documentId,
|
||||
$jaminanId
|
||||
);
|
||||
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
|
||||
$nomorLaporan = getNomorLaporan($permohonanId, $documentId);
|
||||
$tanggalLaporan = $lpj->created_at ?? null;
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
|
||||
if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
$formFoto = json_decode($inspeksi->foto_form, true);
|
||||
// $denahForm = json_decode($data->denah_form, true);
|
||||
$dataPembanding = json_decode($inspeksi->data_pembanding, true);
|
||||
}
|
||||
return $this->previewLaporanService->printOutLaporan($permohonan_id, $document_id, $jaminan_id);
|
||||
|
||||
if ($lpj) {
|
||||
$lpjData = json_decode($lpj->lpj, true);
|
||||
$memo = json_decode($lpj->memo, true);
|
||||
$resumeData = json_decode($lpj->resume, true);
|
||||
$rap = json_decode($lpj->rap, true);
|
||||
$report = json_decode($lpj->call_report, true);
|
||||
}
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$viewLaporan = $this->getViewLaporan($tipeLaporan);
|
||||
try {
|
||||
|
||||
if ($statusLpj) {
|
||||
// $pdf = view('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
// return $pdf;
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return response($pdf->output(), 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'inline; filename="Laporan_' . $tipeLaporan . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan . '.pdf"');
|
||||
// return $pdf->stream();
|
||||
} else {
|
||||
// $pdf = view('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
// return $pdf;
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return $pdf->download('Laporan_' . $tipeLaporan . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan . '_data.pdf');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('PDF generation failed: ' . $e->getMessage());
|
||||
return response()->json(['error' => 'Failed to generate PDF. Please check the log for details.' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function getViewLaporan($tipe)
|
||||
{
|
||||
$viewMap = [
|
||||
'sederhana' => 'penilai.components.print-out-sederhana',
|
||||
'standar' => 'penilai.components.print-out-standar',
|
||||
'resume' => 'penilai.components.print-resume',
|
||||
'memo' => 'penilai.components.print-memo',
|
||||
'rap' => 'penilai.components.print-out-rap',
|
||||
'call-report' => 'penilai.components.print-out-call-report'
|
||||
];
|
||||
return $viewMap[$tipe] ?? 'penilai.components.print-resume';
|
||||
}
|
||||
|
||||
|
||||
@@ -1299,7 +1410,7 @@ class PenilaiController extends Controller
|
||||
}
|
||||
|
||||
|
||||
// pengunaan request query by id permohonan, documentId, jaminan , inspeksi
|
||||
// pengunaan request query by id permohonan, dokument, jaminan , inspeksi
|
||||
protected function getRequestQueryId(Request $request)
|
||||
{
|
||||
return [
|
||||
@@ -1309,7 +1420,46 @@ class PenilaiController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
public function checkPrintOutLaporan(Request $request)
|
||||
{
|
||||
$permohonanId = $request->query('permohonanId');
|
||||
$documentId = $request->query('documentId');
|
||||
|
||||
// Ambil data berdasarkan ID
|
||||
$statusLpj = Penilai::where('permohonan_id', $permohonanId)
|
||||
->where('dokument_id', $documentId)
|
||||
->first();
|
||||
|
||||
// Jika data tidak ditemukan, kembalikan status null
|
||||
if (!$statusLpj) {
|
||||
return response()->json(['status' => null]);
|
||||
}
|
||||
|
||||
// Tentukan tipe berdasarkan kondisi
|
||||
$type = $statusLpj->type_penilai ?? null;
|
||||
|
||||
if ($type === 'memo') {
|
||||
return $this->checkDataMemo($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'resume') {
|
||||
return $this->checkDataResume($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
if ($type === 'standar' || $type === 'sederhana') {
|
||||
return $this->checkDataLpj($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'rap') {
|
||||
return $this->checkDataRap($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Kembalikan respons dengan tipe yang sesuai
|
||||
return response()->json(['status' => $type]);
|
||||
}
|
||||
|
||||
|
||||
public function generateNoLaporan($permohonan, $documentId, $type)
|
||||
@@ -1349,6 +1499,239 @@ class PenilaiController extends Controller
|
||||
}
|
||||
|
||||
|
||||
public function checkDataMemo($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->memo, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'memo' => [
|
||||
'kepada',
|
||||
'dari',
|
||||
'nomor_memo',
|
||||
'tanggal',
|
||||
'perihal',
|
||||
'jenis_asset_tidak_sesuai',
|
||||
'lokasi.lokasi',
|
||||
'lokasi.province_code',
|
||||
'lokasi.city_code',
|
||||
'lokasi.district_code',
|
||||
'lokasi.village_code',
|
||||
'lokasi.penilai',
|
||||
'terlampir',
|
||||
'hasil_survey',
|
||||
'kesimpulan_saran',
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data memo terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data memo valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function checkDataResume($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->resume, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'resume' => [
|
||||
'fisik'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
|
||||
// Validasi khusus untuk array fisik dan sesuai_imb
|
||||
if ($field === 'fisik' || $field === 'sesuai_imb') {
|
||||
if (empty($value) || !is_array($value)) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi struktur data di dalam array
|
||||
foreach ($value as $item) {
|
||||
$requiredKeys = ['sertifikat', 'luas_tanah', 'nilai'];
|
||||
foreach ($requiredKeys as $requiredKey) {
|
||||
if (!isset($item[$requiredKey])) {
|
||||
$missingFields[] = $field . '.' . $requiredKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data resume terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data resume valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataLpj($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->lpj, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'lpj' => [
|
||||
'luas_tanah',
|
||||
'nilai_tanah_1',
|
||||
'nilai_tanah_2',
|
||||
'luas_bangunan',
|
||||
'nilai_bangunan_1',
|
||||
'nilai_bangunan_2',
|
||||
'total_nilai_pasar_wajar',
|
||||
'likuidasi',
|
||||
'likuidasi_nilai_1',
|
||||
'likuidasi_nilai_2',
|
||||
'asuransi_luas_bangunan',
|
||||
'asuransi_nilai_1',
|
||||
'asuransi_nilai_2',
|
||||
'npw_tambahan'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
// Penanganan khusus untuk field yang boleh null
|
||||
if (in_array($field, ['sarana_pelengkap_penilai', 'nilai_sarana_pelengkap_1', 'nilai_sarana_pelengkap_2'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi khusus untuk npw_tambahan
|
||||
if ($field === 'npw_tambahan' && is_array($data[$field])) {
|
||||
foreach ($data[$field] as $index => $item) {
|
||||
$requiredKeys = ['name', 'luas', 'nilai_1', 'nilai_2'];
|
||||
foreach ($requiredKeys as $key) {
|
||||
if (!isset($item[$key])) {
|
||||
$missingFields[] = "npw_tambahan[$index].$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data LPJ terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data LPJ valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataRap($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->rap, true) ?? [];
|
||||
|
||||
$requiredFields = [
|
||||
'dari',
|
||||
'kepada',
|
||||
'perihal',
|
||||
'tanggal',
|
||||
'nomor_rap'
|
||||
];
|
||||
|
||||
// Cek apakah ada field yang kosong
|
||||
$missingFields = [];
|
||||
foreach ($requiredFields as $field) {
|
||||
if (!isset($data[$field]) || empty($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data RAP terlebih dahulu.",
|
||||
'missing_fields' => $missingFields
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Jika semua data terisi
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data RAP valid."
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function revisiSurveyor(Request $request, $id)
|
||||
{
|
||||
$permohonan = Permohonan::findOrFail($id);
|
||||
@@ -1379,24 +1762,4 @@ class PenilaiController extends Controller
|
||||
'message' => 'Berhasil Revisi Ke surveyor',
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showLaporanInspeksi(
|
||||
$permohonan_id,
|
||||
$dokumen_id,
|
||||
$jaminan_id,
|
||||
Request $request)
|
||||
{
|
||||
if ($request->type == 'penilai') {
|
||||
$back = route('penilai.show', $permohonan_id);
|
||||
}else{
|
||||
$back = route('surveyor.show', $permohonan_id);
|
||||
}
|
||||
|
||||
return $this->previewLaporanService->previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back);
|
||||
}
|
||||
|
||||
public function showInspectionReportReview($permohonan_id, $dokumen_id, $jaminan_id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
@@ -168,7 +170,7 @@
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
|
||||
if (!Auth::user()->hasAnyRole(['administrator'])) {
|
||||
if (Auth::check() && !empty(Auth::user()->branch_id)) {
|
||||
$query = $query->where('branch_id', Auth::user()->branch_id);
|
||||
}
|
||||
|
||||
@@ -188,12 +190,36 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Log sorting parameters for debugging
|
||||
Log::debug('Sorting parameters', [
|
||||
'sortField' => $request->get('sortField'),
|
||||
'sortOrder' => $request->get('sortOrder')
|
||||
]);
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
|
||||
// Define allowed columns for sorting
|
||||
$allowedColumns = [
|
||||
'nomor_registrasi',
|
||||
'mig_mst_lpj_nomor_jaminan',
|
||||
'tanggal_permohonan',
|
||||
'status',
|
||||
'user_id',
|
||||
'branch_id'
|
||||
];
|
||||
|
||||
// Handle special cases for sorting
|
||||
if ($column === 'pemohon') {
|
||||
$query->orderBy('user_id', $order);
|
||||
} elseif ($column === 'branch') {
|
||||
$query->orderBy('branch_id', $order);
|
||||
} elseif (in_array($column, $allowedColumns)) {
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
@@ -284,7 +310,7 @@
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query()->with('documents')->has('documents', '>', 0)->where('status', '=', 'order');
|
||||
|
||||
if (!Auth::user()->hasAnyRole(['administrator'])) {
|
||||
if (Auth::check() && !empty(Auth::user()->branch_id)) {
|
||||
$query = $query->where('branch_id', Auth::user()->branch_id);
|
||||
}
|
||||
|
||||
@@ -405,7 +431,7 @@
|
||||
}
|
||||
|
||||
// Add created_by
|
||||
$validatedData['created_by'] = auth()->id();
|
||||
$validatedData['created_by'] = Auth::check() ? Auth::id() : null;
|
||||
|
||||
// Create new PermohonanPembatalan
|
||||
$pembatalan = PermohonanPembatalan::create($validatedData);
|
||||
@@ -413,8 +439,8 @@
|
||||
return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval');
|
||||
}
|
||||
|
||||
public function storeAproved(Request $request, $id)
|
||||
: JsonResponse {
|
||||
public function storeAproved(Request $request, $id): JsonResponse
|
||||
{
|
||||
$data = [];
|
||||
if (request()->ajax()) {
|
||||
try {
|
||||
@@ -514,5 +540,4 @@
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\TujuanPenilaian;
|
||||
|
||||
class RekapHarianSoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$total_laporan_debitur = 0;
|
||||
$tujuan_penilaian = TujuanPenilaian::all();
|
||||
return view('lpj::rekap-harian-so.index', compact('tujuan_penilaian', 'total_laporan_debitur'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1556,11 +1556,11 @@ class SurveyorController extends Controller
|
||||
{
|
||||
|
||||
$validated = $request->validate([
|
||||
'documentId' => 'required',
|
||||
'dokument' => 'required',
|
||||
'jenis_jaminan' => 'required'
|
||||
]);
|
||||
|
||||
$dokumentId = $validated['documentId'];
|
||||
$dokumentId = $validated['dokument'];
|
||||
$jaminanId = $validated['jenis_jaminan'];
|
||||
|
||||
$permohonan = $this->getPermohonanJaminanId($id, $dokumentId, $jaminanId);
|
||||
@@ -1644,11 +1644,11 @@ class SurveyorController extends Controller
|
||||
public function denah(Request $request, $id)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'documentId' => 'required',
|
||||
'dokument' => 'required',
|
||||
'jenis_jaminan' => 'required'
|
||||
]);
|
||||
|
||||
$dokumentId = $validated['documentId'];
|
||||
$dokumentId = $validated['dokument'];
|
||||
$jaminanId = $validated['jenis_jaminan'];
|
||||
|
||||
$permohonan = $this->getPermohonanJaminanId($id, $dokumentId, $jaminanId);
|
||||
@@ -1672,11 +1672,11 @@ class SurveyorController extends Controller
|
||||
public function foto(Request $request, $id)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'documentId' => 'required',
|
||||
'dokument' => 'required',
|
||||
'jenis_jaminan' => 'required'
|
||||
]);
|
||||
|
||||
$dokumentId = $validated['documentId'];
|
||||
$dokumentId = $validated['dokument'];
|
||||
$jaminanId = $validated['jenis_jaminan'];
|
||||
$fotoObjekJaminan = FotoObjekJaminan::all();
|
||||
|
||||
@@ -1707,11 +1707,11 @@ class SurveyorController extends Controller
|
||||
// Ambil data permohonan dengan eager loading
|
||||
|
||||
$validated = $request->validate([
|
||||
'documentId' => 'required',
|
||||
'dokument' => 'required',
|
||||
'jenis_jaminan' => 'required'
|
||||
]);
|
||||
|
||||
$dokumentId = $validated['documentId'];
|
||||
$dokumentId = $validated['dokument'];
|
||||
$jaminanId = $validated['jenis_jaminan'];
|
||||
|
||||
$permohonan = $this->getPermohonanJaminanId($id, $dokumentId, $jaminanId);
|
||||
@@ -2718,7 +2718,7 @@ class SurveyorController extends Controller
|
||||
$fileName = 'inspeksi-' . $namaDebiture . '-data.pdf';
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return $pdf->download($fileName);
|
||||
return $pdf->stream($fileName);
|
||||
}
|
||||
|
||||
public function approveReschedule(Request $request, $id)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CategoryDaftarPustakaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required|max:255',
|
||||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$rules['code'] = 'required|max:50|unique:category_daftar_pustaka,code,' . $this->id;
|
||||
} else {
|
||||
$rules['code'] = 'required|max:50|unique:category_daftar_pustaka,code';
|
||||
}
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DaftarPustakaRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
$rules = [
|
||||
'judul' => 'required|max:255',
|
||||
'category_id' => 'required',
|
||||
'deskripsi' => 'nullable',
|
||||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$rules['attachment'] = 'nullable|mimes:pdf,jpg,jpeg,png,gif';
|
||||
} else {
|
||||
$rules['attachment'] = 'required|mimes:pdf,jpg,jpeg,png,gif';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
// use Modules\Lpj\Database\Factories\CategoryDaftarPustakaFactory;
|
||||
|
||||
class CategoryDaftarPustaka extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'category_daftar_pustaka';
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'code',
|
||||
];
|
||||
|
||||
public function daftarPustaka(){
|
||||
return $this->hasMany(DaftarPustaka::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
// use Modules\Lpj\Database\Factories\DaftarPustakaFactory;
|
||||
|
||||
class DaftarPustaka extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'daftar_pustaka';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'category_id',
|
||||
'judul',
|
||||
'attachment',
|
||||
'deskripsi',
|
||||
];
|
||||
|
||||
public function category(){
|
||||
return $this->belongsTo(CategoryDaftarPustaka::class);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class Inspeksi extends Base
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by','dokument_id','data_pembanding','mig_detail_data_jaminan'];
|
||||
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by','dokument_id','data_pembanding'];
|
||||
|
||||
public function permohonan()
|
||||
{
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\DaftarPustaka;
|
||||
|
||||
class DaftarPustakaService
|
||||
{
|
||||
public function storeDaftarPustaka(array $data, $file)
|
||||
{
|
||||
if ($file) {
|
||||
$data['attachment'] = $this->handleUpload($file);
|
||||
}
|
||||
return DaftarPustaka::create($data);
|
||||
}
|
||||
|
||||
public function updateDaftarPustaka($data, $file, $id)
|
||||
{
|
||||
// Ambil data inputan yang diperlukan saja
|
||||
|
||||
$daftarPustaka = DaftarPustaka::findOrFail($id);
|
||||
|
||||
// Jika ada file baru yang diupload
|
||||
if ($file) {
|
||||
// (Opsional) Hapus file lama
|
||||
if ($daftarPustaka->attachment && file_exists(public_path($daftarPustaka->attachment))) {
|
||||
unlink(public_path($daftarPustaka->attachment));
|
||||
}
|
||||
|
||||
// Upload file baru
|
||||
$data['attachment'] = $this->handleUpload($file);
|
||||
}
|
||||
|
||||
// Update data
|
||||
$daftarPustaka->update($data);
|
||||
|
||||
return $daftarPustaka;
|
||||
}
|
||||
|
||||
|
||||
public function deleteDaftarPustaka($id)
|
||||
{
|
||||
return DaftarPustaka::where('id', $id)->delete();
|
||||
}
|
||||
|
||||
public function getDaftarPustakaById($id)
|
||||
{
|
||||
return DaftarPustaka::where('id', $id)->first();
|
||||
}
|
||||
|
||||
// get all with pagination
|
||||
public function getAllDaftarPustaka($request)
|
||||
{
|
||||
$query = DaftarPustaka::query();
|
||||
|
||||
// Filter pencarian
|
||||
if (!empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->orWhere('judul', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Filter kategori
|
||||
if (!empty($request->get('category'))) {
|
||||
$category = explode(',', $request->input('category'));
|
||||
$query->whereIn('category_id', $category);
|
||||
}
|
||||
|
||||
// Default pagination
|
||||
$page = (int) $request->get('page', 1);
|
||||
$size = (int) $request->get('size', 10);
|
||||
|
||||
return $query->paginate($size, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
|
||||
private function handleUpload($file)
|
||||
{
|
||||
$today = now();
|
||||
$folderPath = 'daftar_pustaka/' . $today->format('Y/m/d');
|
||||
|
||||
$fileName = $file->getClientOriginalName();
|
||||
$filePath = $file->storeAs($folderPath, $fileName, 'public');
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\Laporan;
|
||||
use Modules\Lpj\Models\Noc;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
class DashboardService
|
||||
{
|
||||
public function getDashboardData($start_date, $end_date)
|
||||
{
|
||||
$countLpjInternal = $this->getTotalLpjInternal($start_date, $end_date);
|
||||
$countLpjExternal = $this->getTotalLpjEksternal($start_date, $end_date);
|
||||
$countResume = $this->getResumeCabang($start_date, $end_date);
|
||||
$countPendapatan = $this->getPendapatanAppraisal($start_date, $end_date);
|
||||
|
||||
return [
|
||||
'count_lpj_internal' => $countLpjInternal,
|
||||
'count_lpj_eksternal' => $countLpjExternal,
|
||||
'count_resume' => $countResume,
|
||||
'count_pendapatan' => $countPendapatan
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTotalLpjInternal($start_date, $end_date)
|
||||
{
|
||||
$months = $this->getMonthly();
|
||||
$regions = $this->getRegion();
|
||||
$data = [];
|
||||
|
||||
foreach ($months as $index => $month) {
|
||||
$monthNumber = $index + 1;
|
||||
$data[$month] = [];
|
||||
|
||||
foreach ($regions as $region) {
|
||||
if ($monthNumber > now()->month) {
|
||||
|
||||
$data[$month][$region] = [
|
||||
'total_laporan' => 0,
|
||||
'total_debiture' => 0,
|
||||
];
|
||||
} else {
|
||||
|
||||
$totalLaporan = Laporan::whereBetween('created_at', [$start_date, $end_date])
|
||||
->count();
|
||||
$totalDebitur = Permohonan::whereBetween('created_at', [$start_date, $end_date])
|
||||
->where('status', 'done')
|
||||
->distinct()
|
||||
->count('debiture_id');
|
||||
|
||||
|
||||
|
||||
$data[$month][$region] = [
|
||||
'total_laporan' => $totalLaporan,
|
||||
'total_debiture' => $totalDebitur,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getPendapatanAppraisal($start_date, $end_date)
|
||||
{
|
||||
$months = $this->getMonthly();
|
||||
$data = [];
|
||||
|
||||
foreach ($months as $index => $month) {
|
||||
$monthNumber = $index + 1;
|
||||
|
||||
if ($monthNumber > now()->month) {
|
||||
// Bulan belum terjadi
|
||||
$data[$month] = [
|
||||
'total_jumlah' => 0,
|
||||
'total_akumulasi' => 0,
|
||||
];
|
||||
} else {
|
||||
// Hitung jumlah nominal_bayar pada bulan ini
|
||||
$totalJumlah = Noc::whereYear('tanggal_pembayaran', now()->year)
|
||||
->whereMonth('tanggal_pembayaran', $monthNumber)
|
||||
->sum('nominal_bayar');
|
||||
|
||||
|
||||
$data[$month] = [
|
||||
'total_jumlah' => $totalJumlah,
|
||||
'total_akumulasi' => $totalJumlah,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getResumeCabang($start_date, $end_date)
|
||||
{
|
||||
$regions = $this->getRegion();
|
||||
$status = ['batal', 'done'];
|
||||
$data = [];
|
||||
|
||||
foreach ($status as $item) {
|
||||
$data[$item] = [];
|
||||
foreach ($regions as $region) {
|
||||
$totalLaporan = DB::table('laporan')
|
||||
->join('permohonan', 'laporan.permohonan_id', '=', 'permohonan.id')
|
||||
->where('permohonan.status', $item)
|
||||
->whereBetween('laporan.created_at', [$start_date, $end_date])
|
||||
->count();
|
||||
|
||||
$data[$item][$region] = [
|
||||
'count_report' => $totalLaporan,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
public function getTotalLpjEksternal($start_date, $end_date)
|
||||
{
|
||||
$months = $this->getMonthly();
|
||||
$data = [];
|
||||
foreach ($months as $index => $month) {
|
||||
$monthNumber = $index + 1;
|
||||
if ($monthNumber > now()->month) {
|
||||
$data[$month] = [
|
||||
'total_laporan' => 0,
|
||||
'total_debiture' => 0,
|
||||
];
|
||||
} else {
|
||||
$totalLaporan = Laporan::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
|
||||
|
||||
$totalDebitur = Permohonan::whereBetween('created_at', [$start_date, $end_date])
|
||||
->where('status', 'done')
|
||||
->distinct()
|
||||
->count('debiture_id');
|
||||
|
||||
$data[$month] = [
|
||||
'total_laporan' => $totalLaporan,
|
||||
'total_debiture' => $totalDebitur,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getMonthly()
|
||||
{
|
||||
return [
|
||||
'januari',
|
||||
'februari',
|
||||
'maret',
|
||||
'april',
|
||||
'mei',
|
||||
'juni',
|
||||
'juli',
|
||||
'agustus',
|
||||
'september',
|
||||
'oktober',
|
||||
'november',
|
||||
'desember',
|
||||
];
|
||||
}
|
||||
|
||||
private function getRegion()
|
||||
{
|
||||
return [
|
||||
'jabodetabek',
|
||||
'non-jabodetabek',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
|
||||
class LaporanBiayaService
|
||||
{
|
||||
public function buildDataTableQuery(array $data){
|
||||
$query = Permohonan::with([
|
||||
'noc'
|
||||
]);
|
||||
|
||||
if($data['search']){
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Illuminate\Http\Request;
|
||||
class LaporanDebitureService
|
||||
{
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
$query = $query->where('status', 'done');
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
|
||||
if (isset($search->start_date) || isset($search->end_date)) {
|
||||
$query->whereBetween('tanggal_permohonan', [
|
||||
$search->start_date ?? '1900-01-01',
|
||||
$search->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
// Filter by branch if provided
|
||||
if (isset($search->debiture_id) && !empty($search->debiture_id)) {
|
||||
$query->where('debiture_id', $search->debiture_id);
|
||||
}
|
||||
|
||||
if (isset($search->search)) {
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->search . '%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with(['debiture.branch'])->get();
|
||||
|
||||
$data = $data->map(function ($permohonan) {
|
||||
$luas_tanah = 0;
|
||||
$luas_bangunan = 0;
|
||||
$nilai_tanah = 0;
|
||||
$nilai_bangunan = 0;
|
||||
$npw = 0;
|
||||
$nilai_liquidasi = 0;
|
||||
|
||||
if (isset($permohonan->penilai->lpj)) {
|
||||
$lpj = json_decode($permohonan->penilai->lpj, true);
|
||||
$npw = str_replace('.', '', $lpj['total_nilai_pasar_wajar'] ?? 0);
|
||||
|
||||
$luas_tanah = $lpj['luas_tanah'] ?? 0;
|
||||
$luas_bangunan = $lpj['luas_bangunan'] ?? 0;
|
||||
// Calculate nilai_tanah dynamically by looking for all keys that start with 'nilai_tanah_'
|
||||
$nilai_tanah = str_replace('.', '', $lpj['nilai_tanah_2'] ?? 0);
|
||||
|
||||
$nilai_bangunan = str_replace('.', '', $lpj['nilai_bangunan_2'] ?? 0);
|
||||
$nilai_liquidasi = str_replace('.', '', $lpj['likuidasi_nilai_2'] ?? 0);
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $permohonan->id,
|
||||
'nomor_registrasi' => $permohonan->nomor_registrasi,
|
||||
'jenis_penilaian' => $permohonan->jenisPenilaian?->name,
|
||||
'tujuan_penilaian' => $permohonan->tujuanPenilaian?->name,
|
||||
'jenis_fasilitas_kredit' => $permohonan->jenisFasilitasKredit?->name,
|
||||
'branch' => $permohonan->debiture->branch?->name,
|
||||
'pemohon' => $permohonan->creator?->name,
|
||||
'cif' => $permohonan->debiture->cif,
|
||||
'name' => $permohonan->debiture?->name,
|
||||
'jenis_agunan' => $permohonan->documents?->pluck('jenisJaminan.name')
|
||||
->unique()
|
||||
->implode(', '),
|
||||
'alamat_agunan' => $permohonan->documents?->map(function ($document) {
|
||||
return formatAlamat($document);
|
||||
})->unique()->implode(', '),
|
||||
'bukti_kepemilikan' => (function () use ($permohonan) {
|
||||
$legalitasItems = $permohonan->documents?->flatMap(function ($document) {
|
||||
return $document->detail->map(function ($detail) {
|
||||
// Jika tidak ada jenis legalitas jaminan, lewati
|
||||
if (empty($detail->jenisLegalitasJaminan)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Hanya tampilkan detail yang memiliki dokumen_jaminan
|
||||
if (empty($detail->dokumen_jaminan)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Tampilkan nama legalitas jaminan saja
|
||||
return $detail->jenisLegalitasJaminan->name ?? '';
|
||||
});
|
||||
})->filter()->unique()->values()->toArray();
|
||||
|
||||
// Buat daftar bernomor
|
||||
$result = '';
|
||||
foreach ($legalitasItems as $index => $item) {
|
||||
$result .= ($index + 1) . '. ' . $item . "\n";
|
||||
}
|
||||
|
||||
return $result;
|
||||
})(),
|
||||
'nama_pemilik' => $permohonan->documents?->pluck('pemilik.name')
|
||||
->unique()
|
||||
->implode(', '),
|
||||
'luas_tanah' => $luas_tanah . ' m²',
|
||||
'nilai_tanah' => formatRupiah($nilai_tanah, 2),
|
||||
'luas_bangunan' => $luas_bangunan . ' m²',
|
||||
'nilai_bangunan' => formatRupiah($nilai_bangunan, 2),
|
||||
'nilai_njop' => formatRupiah($permohonan->nilai_njop, 2),
|
||||
'nilai_pasar_wajar' => formatRupiah($npw, 2),
|
||||
'nilai_likuidasi' => formatRupiah($nilai_liquidasi, 2),
|
||||
'tanggal_documen_diterima' => $permohonan->documents?->map(function ($document) {
|
||||
return $document->created_at->format('d-m-Y');
|
||||
}),
|
||||
'tanggal_spk' => '',
|
||||
'nomor_spk' => '',
|
||||
'tanggal_rencana_kunjunagn' => '',
|
||||
'tanggal_kunjungan' => '',
|
||||
'taggal_delivered' => '',
|
||||
'jangka_waktu_sla' => '',
|
||||
'nama_penilai' => $permohonan->penilaian?->_user_penilai?->userPenilaiTeam?->name,
|
||||
'nama_team_leader' => $permohonan->penilaian?->teams,
|
||||
'saran' => '',
|
||||
'catatan' => '',
|
||||
|
||||
|
||||
'tanggal_permohonan' => $permohonan->tanggal_permohonan,
|
||||
'tanggal_laporan' => $permohonan->approval_dd_at ?? $permohonan->approval_eo_at ?? '',
|
||||
'tanggal_review' => $permohonan->penilaian?->tanggal_kunjungan ?? '',
|
||||
];
|
||||
});
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page') ?: 1;
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
use Modules\Lpj\Models\TeamsUsers;
|
||||
use Modules\Lpj\Models\Teams;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\StatusPermohonan;
|
||||
use Carbon\Carbon;
|
||||
class LaporanMonitoringSoService
|
||||
{
|
||||
|
||||
public function progresPengerjaanLaporan($user){
|
||||
|
||||
// Inisialisasi regionId dan teamId
|
||||
$regionId = $teamId = null;
|
||||
|
||||
if ($user->roles->pluck('name')->contains('senior-officer')) {
|
||||
$userTeam = TeamsUsers::with('team')->firstWhere('user_id', $user->id);
|
||||
$regionId = $userTeam?->team->regions_id;
|
||||
$teamId = $userTeam?->teams_id;
|
||||
}
|
||||
|
||||
|
||||
$teamsActivity = TeamsUsers::with(['user', 'team', 'team.regions', 'user.roles'])
|
||||
->whereHas('team', function ($q) use ($regionId, $teamId) {
|
||||
$q->when($regionId, fn ($q) => $q->where('regions_id', $regionId))
|
||||
->when($teamId, fn ($q) => $q->where('id', $teamId));
|
||||
})
|
||||
->where('user_id', '!=', $user->id)
|
||||
->whereHas('user.roles', fn ($q) => $q->whereIn('name', ['surveyor', 'surveyor-penilai']))
|
||||
->get();
|
||||
|
||||
$teamId = is_array($teamId) ? $teamId : [$teamId];
|
||||
|
||||
$teamPenilai = Teams::with(['regions', 'teamsUsers', 'teamsUsers.user'])->whereNotIn(
|
||||
'id',
|
||||
$teamId
|
||||
)->get();
|
||||
|
||||
return [
|
||||
'teamsActivity' => $teamsActivity,
|
||||
'teamPenilai' => $teamPenilai,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function showDetailsPermohonan($request,$id)
|
||||
{
|
||||
$query = Penilaian::with([
|
||||
'permohonan',
|
||||
'permohonan.debiture',
|
||||
'permohonan.tujuanPenilaian',
|
||||
'permohonan.debiture.documents.jenisJaminan',
|
||||
'userPenilai' => function ($query) use ($id) {
|
||||
$query->where('user_id', $id);
|
||||
},
|
||||
'permohonan.penilai',
|
||||
'permohonan.approveEo',
|
||||
'permohonan.approveDd',
|
||||
'permohonan.approveSo',
|
||||
|
||||
])
|
||||
->whereHas('userPenilai', function ($q) use ($id) {
|
||||
$q->where('user_id', $id);
|
||||
})
|
||||
->whereHas('permohonan', function ($q) {
|
||||
$q->whereIn('status', [
|
||||
'assign',
|
||||
'survey-completed',
|
||||
'proses-laporan',
|
||||
'paparan',
|
||||
'proses-paparan',
|
||||
'revisi-laporan',
|
||||
'revisi-paparan',
|
||||
'survey',
|
||||
'proses-survey',
|
||||
'request-reschedule',
|
||||
'reschedule',
|
||||
'rejected-reschedule',
|
||||
'approved-reschedule',
|
||||
'revisi-survey',
|
||||
'revisi-pembayaran'
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Filter pencarian
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', "%$search%")
|
||||
->orWhere('status', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Sorting
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Hitung total records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Pagination
|
||||
$size = $request->get('size', 10);
|
||||
$page = $request->get('page', 1);
|
||||
$offset = ($page - 1) * $size;
|
||||
|
||||
// Ambil data dengan pagination
|
||||
$data = $query->skip($offset)->take($size)->get();
|
||||
|
||||
$data = $data->map(function ($item) {
|
||||
$jeniAsset = null;
|
||||
$statusPembayaran = trim(strtolower($item->permohonan->status_bayar ?? ''));
|
||||
$tujuanPenilaian = $item->permohonan->tujuanPenilaian->name ?? null;
|
||||
$plafond = $item->permohonan->nilaiPlafond->name ?? null;
|
||||
|
||||
$now = Carbon::now();
|
||||
$type_report = $item->permohonan->penilai->type ?? "";
|
||||
|
||||
$hari = $hariPaparan = 0;
|
||||
|
||||
if ($type_report == "sederhana") {
|
||||
$hari = 2;
|
||||
$item->paparan = 'Tidak Ada';
|
||||
} else {
|
||||
if ($plafond == '< 2M') {
|
||||
$item->paparan = 'Tidak Ada';
|
||||
$hari = 3;
|
||||
} elseif ($plafond == '2 M - 5 M') {
|
||||
$hari = 3;
|
||||
$hariPaparan = 2;
|
||||
} else {
|
||||
$hari = 5;
|
||||
$hariPaparan = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tujuanPenilaian == 'RAP') {
|
||||
$hari = 2;
|
||||
$hariPaparan = 2;
|
||||
}
|
||||
|
||||
|
||||
if ($item->permohonan && $item->permohonan->debiture) {
|
||||
$jeniAsset = $item->permohonan->debiture->documents->first() ?? null;
|
||||
}
|
||||
|
||||
/*$hariTambahan = 0;
|
||||
|
||||
if ($tujuanPenilaian == 'RAP') {
|
||||
$hariTambahan = 2;
|
||||
} else {
|
||||
if ($statusPembayaran == 'sudah_bayar') {
|
||||
$hariTambahan = 1; // H+1 untuk yang sudah bayar
|
||||
} else {
|
||||
$hariTambahan = 2; // H+2 untuk yang belum bayar
|
||||
}
|
||||
}*/
|
||||
|
||||
$tanggalMulai = $item->waktu_penilaian;
|
||||
|
||||
if ($tanggalMulai) {
|
||||
if (!$tanggalMulai instanceof Carbon) {
|
||||
$tanggalMulai = Carbon::parse($tanggalMulai);
|
||||
}
|
||||
$hariKerjaBerikutnya = hitungHariKerja($tanggalMulai->toDateString(), $tanggalMulai->copy()->addDays(1));
|
||||
$hariKerjaBerikutnya = max($hariKerjaBerikutnya, 1);
|
||||
$tanggalMulai = $tanggalMulai->copy()->addDays($hariKerjaBerikutnya);
|
||||
|
||||
// Konversi string tanggal ke objek Carbon jika belum
|
||||
if (!$tanggalMulai instanceof Carbon) {
|
||||
$tanggalMulai = Carbon::parse($tanggalMulai);
|
||||
}
|
||||
|
||||
// Hitung tanggal selesai berdasarkan hari tambahan
|
||||
$tanggalSelesai = $tanggalMulai->copy()->addDays($hari);
|
||||
$tanggalPaparan = $tanggalMulai->copy()->addDays($hariPaparan);
|
||||
|
||||
// Hitung hari kerja
|
||||
$hariKerja = hitungHariKerja($tanggalMulai->toDateString(), $tanggalSelesai->toDateString());
|
||||
$hariKerja = max($hariKerja, $hari);
|
||||
|
||||
$hariKerjaPaparan = hitungHariKerja($tanggalMulai->toDateString(), $tanggalPaparan->toDateString());
|
||||
$hariKerjaPaparan = max($hariKerjaPaparan, $hariPaparan);
|
||||
|
||||
// Set due date SLA
|
||||
$dueDateSla = $tanggalMulai->copy()->addDays($hariKerja);
|
||||
$dueDateSlaPaparan = $tanggalMulai->copy()->addDays($hariKerjaPaparan);
|
||||
|
||||
// Cek apakah sudah melewati due date
|
||||
/*if ($now->greaterThan($dueDateSla)) {
|
||||
$item->due_date_sla = null;
|
||||
} else {
|
||||
$item->due_date_sla = $dueDateSla->toDateString();
|
||||
}*/
|
||||
|
||||
$item->due_date_sla = $dueDateSla->toDateString();
|
||||
$item->paparan = $dueDateSlaPaparan->toDateString();
|
||||
} else {
|
||||
$item->due_date_sla = null;
|
||||
$item->paparan = null;
|
||||
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
$filteredRecords = $data->count();
|
||||
$pageCount = ceil($totalRecords / $size);
|
||||
|
||||
// Return data dalam bentuk JSON
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $page,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class LaporanSLAPenilaiService
|
||||
{
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
$query = $query->where('status', 'done');
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
|
||||
if (isset($search->start_date) || isset($search->end_date)) {
|
||||
$query->whereBetween('tanggal_permohonan', [
|
||||
$search->start_date ?? '1900-01-01',
|
||||
$search->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if (isset($search->penilai_id) && !empty($search->penilai_id)) {
|
||||
$query->whereHas('penilaian._user_penilai.userPenilaiTeam', function ($q) use ($search) {
|
||||
$q->where('user_id', $search->penilai_id);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($search->search)) {
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisFasilitasKredit', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhereRelation('jenisPenilaian', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->search . '%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with(['documents','debiture.branch'])->get();
|
||||
|
||||
$data = $data->map(function ($permohonan) {
|
||||
|
||||
$tgl_kunjungan = $permohonan->penilaian?->tanggal_kunjungan;
|
||||
$tgl_otorisator = $permohonan->approval_dd_at ?? $permohonan->approval_eo_at ?? $permohonan->approval_so_at;
|
||||
$jangkaWaktu = $this->hitungTotalJangkaWaktuSla($tgl_kunjungan, $tgl_otorisator);
|
||||
|
||||
|
||||
|
||||
return [
|
||||
'id' => $permohonan->id,
|
||||
'nomor_registrasi' => $permohonan->nomor_registrasi,
|
||||
'tanggal_permohonan' => $permohonan->tanggal_permohonan,
|
||||
'branch' => $permohonan->debiture?->branch?->name,
|
||||
'name' => $permohonan->debiture?->name,
|
||||
'pemohon' => $permohonan->creator?->name,
|
||||
'tujuan_penilaian' => $permohonan->tujuanPenilaian?->name,
|
||||
'tanggal_laporan' => $permohonan->approval_dd_at ?? $permohonan->approval_eo_at ?? '',
|
||||
'tanggal_approval' => $permohonan->approval_dd_at ?? $permohonan->approval_eo_at ?? '',
|
||||
'tanggal_kunjungan' => $permohonan->penilaian?->tanggal_kunjungan ?? '',
|
||||
'nama_penilai' => $permohonan->penilaian?->_user_penilai?->userPenilaiTeam?->name,
|
||||
'jangka_waktu' => $jangkaWaktu,
|
||||
'keterangan' => $permohonan->keterangan
|
||||
];
|
||||
});
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
private function hitungTotalJangkaWaktuSla($tgl_kunjungan,$tgl_otorisator){
|
||||
$countHariKerja = hitungHariKerja($tgl_kunjungan, $tgl_otorisator);
|
||||
return $countHariKerja;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
class LaporanUserService
|
||||
{
|
||||
public function getUserPemohon($search = null)
|
||||
{
|
||||
return Permohonan::join('users', 'users.id', '=', 'permohonan.user_id')
|
||||
->whereNotNull('permohonan.nomor_registrasi')
|
||||
->when($search, function ($query) use ($search) {
|
||||
$query->where('users.name', 'like', "%$search%");
|
||||
})
|
||||
->select('users.id', 'users.name')
|
||||
->distinct()
|
||||
->orderBy('users.name')
|
||||
->limit(20)
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = User::query();
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
if (isset($search->search)) {
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']);
|
||||
$q->where('nik', 'LIKE', '%' . $search->search . '%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with(['branch', 'roles'])->get();
|
||||
|
||||
$data = $data->map(function ($user) {
|
||||
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'nik' => $user->nik,
|
||||
'name' => $user->name,
|
||||
'level' => $user->roles->pluck('name')->implode(', '),
|
||||
'approval_limit' => 0,
|
||||
];
|
||||
});
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page') ?: 1;
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,733 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Helpers\Lpj;
|
||||
use Modules\Lpj\Models\Denah;
|
||||
use Modules\Lpj\Models\Teams;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Models\Lantai;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Modules\Lpj\Models\Analisa;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Lpj\Models\Surveyor;
|
||||
use Modules\Lpj\Models\ViewUnit;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Lpj\Models\JenisUnit;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\Perizinan;
|
||||
use Modules\Lpj\Models\BentukUnit;
|
||||
use Modules\Lpj\Models\JenisKapal;
|
||||
use Modules\Lpj\Models\LantaiUnit;
|
||||
use Modules\Lpj\Models\Lingkungan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\PosisiUnit;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\AnalisaUnit;
|
||||
use Modules\Lpj\Models\BentukTanah;
|
||||
use Modules\Lpj\Models\FotoJaminan;
|
||||
use Modules\Lpj\Models\KonturTanah;
|
||||
use Modules\Lpj\Models\RuteJaminan;
|
||||
use Modules\Location\Models\Village;
|
||||
use Modules\Lpj\Models\AnalisaFakta;
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\JenisPesawat;
|
||||
use Modules\Lpj\Models\ObjekJaminan;
|
||||
use Modules\Lpj\Models\SpekBangunan;
|
||||
use Modules\Lpj\Models\TerletakArea;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Lpj\Models\ArahMataAngin;
|
||||
use Modules\Lpj\Models\JenisBangunan;
|
||||
use Modules\Lpj\Models\PosisiKavling;
|
||||
use Modules\Lpj\Models\SifatBangunan;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\FasilitasObjek;
|
||||
use Modules\Lpj\Models\JenisKendaraan;
|
||||
use Modules\Lpj\Models\ModelAlatBerat;
|
||||
use Modules\Lpj\Models\KetinggianTanah;
|
||||
use Modules\Lpj\Models\KondisiBangunan;
|
||||
use Modules\Lpj\Models\LaporanExternal;
|
||||
use Modules\Lpj\Models\MerupakanDaerah;
|
||||
use Modules\Lpj\Models\PerkerasanJalan;
|
||||
use Modules\Lpj\Models\SaranaPelengkap;
|
||||
use Modules\Lpj\Models\TujuanPenilaian;
|
||||
use Modules\Lpj\Models\FotoObjekJaminan;
|
||||
use Modules\Lpj\Models\LaluLintasLokasi;
|
||||
use Modules\Lpj\Models\TingkatKeramaian;
|
||||
use Modules\Lpj\Models\AnalisaLingkungan;
|
||||
use Modules\Lpj\Models\KondisiFisikTanah;
|
||||
use Modules\Lpj\Models\AnalisaTanahBagunan;
|
||||
use Modules\Lpj\Models\GolonganMasySekitar;
|
||||
use Modules\Lpj\Models\SpekBangunanAnalisa;
|
||||
use Modules\Lpj\Models\DetailDokumenJaminan;
|
||||
use Modules\Lpj\Models\SpekKategoritBangunan;
|
||||
use Modules\Lpj\Http\Requests\SurveyorRequest;
|
||||
use Modules\Lpj\Models\HubunganPemilikJaminan;
|
||||
use Modules\Lpj\Models\HubunganPenghuniJaminan;
|
||||
use Modules\Lpj\Models\SpekBagunanAnalisaDetail;
|
||||
use Modules\Lpj\Jobs\SendJadwalKunjunganEmailJob;
|
||||
use Modules\Lpj\Http\Requests\FormSurveyorRequest;
|
||||
|
||||
class PreviewLaporanService
|
||||
{
|
||||
/**
|
||||
* Preview Laporan dan unduh foto terkait dengan logika fallback path.
|
||||
*
|
||||
* Menghasilkan PDF atau paket unduhan foto berdasarkan status laporan.
|
||||
* Jika file foto asli tidak ditemukan dan status LPJ adalah 1, maka
|
||||
* sistem akan mencoba menggunakan fallback path dengan pola
|
||||
* `surveyor/001/{lastTwoParts}` untuk meminimalisir gambar hilang.
|
||||
*
|
||||
* @param int $permohonan_id ID Permohonan
|
||||
* @param int $dokumen_id ID Dokumen
|
||||
* @param int $jaminan_id ID Jaminan
|
||||
* @param string $back URL atau rute kembali
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back)
|
||||
{
|
||||
$permohonan = $this->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$dokumen_id,
|
||||
$jaminan_id
|
||||
);
|
||||
// $tipeLaporanResponse = $this->checkPrintOutLaporan($permohonan_id, $document_id);
|
||||
// $tipeLaporan = $tipeLaporanResponse->getData();
|
||||
|
||||
// if (!$tipeLaporan->status) {
|
||||
// return redirect()->back()->with('error', 'Laporan tidak valid');
|
||||
// }
|
||||
$basicData = $this->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonan_id)->where('dokument_id', $dokumen_id)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonan_id)->where('dokument_id', $dokumen_id)->first();
|
||||
|
||||
$mig_permohonan = json_decode($permohonan->mig_permohonan);
|
||||
|
||||
$nomorLaporan = getNomorLaporan($permohonan_id, $dokumen_id);
|
||||
$tanggalLaporan = $permohonan->is_mig
|
||||
? ($mig_permohonan->mig_mst_jaminan_tgl_laporan ?? $mig_permohonan->mig_mst_jaminan_tgl_create ?? null)
|
||||
: ($lpj->created_at ?? null);
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
|
||||
// if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi?->data_form, true) ?? null;
|
||||
|
||||
$formFoto = json_decode($inspeksi?->foto_form, true) ?? null;
|
||||
// $denahForm = json_decode($data->denah_form, true);
|
||||
$dataPembanding = json_decode($inspeksi?->data_pembanding, true) ?? null;
|
||||
// }
|
||||
|
||||
// if ($lpj) {
|
||||
$lpjData = json_decode($lpj?->lpj, true) ?? null;
|
||||
$memo = json_decode($lpj?->memo, true) ?? null;
|
||||
$resumeData = json_decode($lpj?->resume, true) ?? null;
|
||||
$rap = json_decode($lpj?->rap, true);
|
||||
$report = json_decode($lpj?->call_report, true) ?? null;
|
||||
// }
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$statusLpj = 0;
|
||||
|
||||
// $viewLaporan = $this->getViewLaporan($tipeLaporan);
|
||||
return view('lpj::component.show-laporan-inspeksi', compact('permohonan', 'basicData', 'forminspeksi', 'alamat', 'lpjData', 'memo', 'resumeData', 'rap', 'report', 'lpj', 'formFoto', 'nomorLaporan', 'tanggalLaporan', 'dataPembanding', 'inspeksi', 'statusLpj', 'permohonan_id', 'back', ));
|
||||
}
|
||||
|
||||
public function printOutLaporan($permohonan_id, $document_id, $jaminan_id)
|
||||
{
|
||||
$tipeLaporanResponse = $this->checkPrintOutLaporan($permohonan_id, $document_id);
|
||||
$tipeLaporan = $tipeLaporanResponse->getData();
|
||||
|
||||
//dd($permohonan_id, $document_id, $tipeLaporan);
|
||||
|
||||
if (!$tipeLaporan->status) {
|
||||
//return redirect()->back()->with('error', 'Laporan tidak valid');
|
||||
}
|
||||
$permohonan = $this->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$document_id,
|
||||
$jaminan_id
|
||||
);
|
||||
|
||||
$basicData = $this->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonan_id)->where('dokument_id', $document_id)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonan_id)->first(); //->where('dokument_id', $document_id)->first();
|
||||
|
||||
$mig_permohonan = json_decode($permohonan->mig_permohonan);
|
||||
$nomorLaporan = getNomorLaporan($permohonan_id, $document_id);
|
||||
|
||||
//Carbon::createFromFormat('d/m/Y H:i:s', $mig_permohonan->mig_mst_jaminan_tgl_laporan)->format('Y-m-d H:i:s');
|
||||
|
||||
$tanggalLaporan = $permohonan->is_mig
|
||||
? ($mig_permohonan->mig_mst_jaminan_tgl_laporan
|
||||
? Carbon::createFromFormat('d/m/Y H:i:s', $mig_permohonan->mig_mst_jaminan_tgl_laporan)->format('Y-m-d H:i:s')
|
||||
: ($mig_permohonan->mig_mst_jaminan_tgl_oto
|
||||
? Carbon::createFromFormat('d/m/Y H:i:s', $mig_permohonan->mig_mst_jaminan_tgl_oto)->format('Y-m-d H:i:s')
|
||||
: null))
|
||||
: ($lpj->created_at ?? null);
|
||||
|
||||
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
|
||||
$dataPembanding ='';
|
||||
if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
$formFoto = json_decode($inspeksi->foto_form, true);
|
||||
// $denahForm = json_decode($data->denah_form, true);
|
||||
$dataPembanding = json_decode($inspeksi->data_pembanding, true);
|
||||
}
|
||||
|
||||
|
||||
if ($lpj) {
|
||||
$lpjData = json_decode($lpj->lpj, true);
|
||||
$memo = json_decode($lpj->memo, true);
|
||||
$resumeData = json_decode($lpj->resume, true);
|
||||
$rap = json_decode($lpj->rap, true);
|
||||
$report = json_decode($lpj->call_report, true);
|
||||
}
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$viewLaporan = $this->getViewLaporan($tipeLaporan->status);
|
||||
|
||||
$statusLpj = 1;
|
||||
|
||||
$mig_permohonan = json_decode($permohonan->mig_permohonan);
|
||||
if(($tipeLaporan->status === 'memo' && $permohonan->mig_permohonan) || $mig_permohonan->mig_mst_lpj_tot_nilai_pasar < 1){
|
||||
$paths = $formFoto['upload_foto'] ?? null;
|
||||
|
||||
if (!is_array($paths) || empty($paths)) {
|
||||
return response()->json(['error' => 'No files to download'], 404);
|
||||
}
|
||||
|
||||
$files = [];
|
||||
foreach ($paths as $path) {
|
||||
if (!$path['path']) {
|
||||
Log::warning('PreviewLaporanService: Path kosong terdeteksi dalam daftar paths.');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Logika fallback untuk path file
|
||||
$originalPath = $path['path'];
|
||||
$fallbackPath = null;
|
||||
|
||||
// Jika file asli tidak ditemukan, buat fallback path
|
||||
if ($statusLpj == 1) {
|
||||
$fullOriginalPath = storage_path('app/public/' . $originalPath);
|
||||
|
||||
if (!file_exists($fullOriginalPath)) {
|
||||
// Ekstrak bagian akhir path (contoh: 251051/251051_2_2.png)
|
||||
$pathParts = explode('/', $originalPath);
|
||||
if (count($pathParts) >= 2) {
|
||||
$lastTwoParts = array_slice($pathParts, -2);
|
||||
$fallbackPath = 'surveyor/001/' . implode('/', $lastTwoParts);
|
||||
Log::info('PreviewLaporanService: Menggunakan fallback path kandidat.', [
|
||||
'original' => $originalPath,
|
||||
'fallback' => $fallbackPath,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tentukan path yang akan digunakan
|
||||
$pathToUse = ($fallbackPath && $statusLpj == 1 && file_exists(storage_path('app/public/' . $fallbackPath)))
|
||||
? $fallbackPath
|
||||
: $originalPath;
|
||||
|
||||
$fullPath = storage_path('app/public/' . $pathToUse);
|
||||
if (!file_exists($fullPath)) {
|
||||
Log::warning('PreviewLaporanService: File tidak ditemukan untuk original maupun fallback.', [
|
||||
'original' => $originalPath,
|
||||
'fallback' => $fallbackPath,
|
||||
'resolved' => $pathToUse,
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
|
||||
Log::info('PreviewLaporanService: Menambahkan file untuk diunduh.', [
|
||||
'resolved' => $pathToUse,
|
||||
'fullPath' => $fullPath,
|
||||
]);
|
||||
$files[] = $fullPath;
|
||||
}
|
||||
|
||||
if (empty($files)) {
|
||||
Log::warning('PreviewLaporanService: Tidak ada file valid ditemukan setelah resolusi path.');
|
||||
return response()->json(['error' => 'No valid files found'], 404);
|
||||
}
|
||||
|
||||
// For single file, download directly
|
||||
if (count($files) === 1) {
|
||||
Log::info('PreviewLaporanService: Mengunduh single file.', ['file' => $files[0]]);
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
// For multiple files, create zip and download
|
||||
$zipName = 'photos_' . time() . '.zip';
|
||||
$zipPath = storage_path('app/public/' . $zipName);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($zipPath, \ZipArchive::CREATE) === true) {
|
||||
foreach ($files as $file) {
|
||||
$zip->addFile($file, basename($file));
|
||||
}
|
||||
$zip->close();
|
||||
Log::info('PreviewLaporanService: Zip file berhasil dibuat.', ['zip' => $zipPath, 'count' => count($files)]);
|
||||
return response()->download($zipPath)->deleteFileAfterSend(true);
|
||||
}
|
||||
|
||||
Log::error('PreviewLaporanService: Gagal membuat zip file.');
|
||||
return response()->json(['error' => 'Failed to create zip file'], 500);
|
||||
}
|
||||
try {
|
||||
$pdf = $this->generatePDF($viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$filename = 'Laporan_' . $tipeLaporan->status . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan;
|
||||
|
||||
return $pdf->download($filename . '_data.pdf');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('PDF generation failed: ' . $e->getMessage());
|
||||
return response()->json(['error' => 'Failed to generate PDF. Please check the log for details.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function generatePDF(string $viewLaporan, array $data)
|
||||
{
|
||||
//return view('lpj::' . $viewLaporan, $data);
|
||||
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
|
||||
private function getViewLaporan($tipe)
|
||||
{
|
||||
$viewMap = [
|
||||
'sederhana' => 'penilai.components.print-out-sederhana',
|
||||
'standar' => 'penilai.components.print-out-standar',
|
||||
'resume' => 'penilai.components.print-resume',
|
||||
'memo' => 'penilai.components.print-memo',
|
||||
'rap' => 'penilai.components.print-out-rap',
|
||||
'call-report' => 'penilai.components.print-out-call-report'
|
||||
];
|
||||
return $viewMap[$tipe] ?? 'penilai.components.print-resume';
|
||||
}
|
||||
|
||||
public function checkPrintOutLaporan($permohonan_id, $dokumen_id)
|
||||
{
|
||||
|
||||
// Ambil data berdasarkan ID
|
||||
$statusLpj = Penilai::where('permohonan_id', $permohonan_id)
|
||||
//->where('dokument_id', $dokumen_id)
|
||||
->first();
|
||||
|
||||
|
||||
$permohonan = Permohonan::where('id', $permohonan_id)->first();
|
||||
|
||||
// Jika data tidak ditemukan, kembalikan status null
|
||||
if (!$statusLpj) {
|
||||
return response()->json(['status' => null]);
|
||||
}
|
||||
|
||||
// Tentukan tipe berdasarkan kondisi
|
||||
$type = $statusLpj->type_penilai ?? null;
|
||||
|
||||
if ($type === 'memo' && $permohonan->is_mig!=1) {
|
||||
return $this->checkDataMemo($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'resume') {
|
||||
return $this->checkDataResume($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
if ($type === 'standar' || $type === 'sederhana') {
|
||||
return $this->checkDataLpj($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'rap') {
|
||||
return $this->checkDataRap($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Kembalikan respons dengan tipe yang sesuai
|
||||
return response()->json(['status' => $type]);
|
||||
}
|
||||
|
||||
public function checkDataMemo($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->memo, true) ?? [];
|
||||
|
||||
|
||||
$validationRules = [
|
||||
'memo' => [
|
||||
'kepada',
|
||||
'dari',
|
||||
'nomor_memo',
|
||||
'tanggal',
|
||||
'perihal',
|
||||
'jenis_asset_tidak_sesuai',
|
||||
'lokasi.lokasi',
|
||||
'lokasi.province_code',
|
||||
'lokasi.city_code',
|
||||
'lokasi.district_code',
|
||||
'lokasi.village_code',
|
||||
'lokasi.penilai',
|
||||
'terlampir',
|
||||
'hasil_survey',
|
||||
'kesimpulan_saran',
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data memo terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data memo valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function checkDataResume($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->resume, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'resume' => [
|
||||
'fisik'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
|
||||
// Validasi khusus untuk array fisik dan sesuai_imb
|
||||
if ($field === 'fisik' || $field === 'sesuai_imb') {
|
||||
if (empty($value) || !is_array($value)) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi struktur data di dalam array
|
||||
foreach ($value as $item) {
|
||||
$requiredKeys = ['sertifikat', 'luas_tanah', 'nilai'];
|
||||
foreach ($requiredKeys as $requiredKey) {
|
||||
if (!isset($item[$requiredKey])) {
|
||||
$missingFields[] = $field . '.' . $requiredKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data resume terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data resume valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataLpj($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->lpj, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'lpj' => [
|
||||
'luas_tanah',
|
||||
'nilai_tanah_1',
|
||||
'nilai_tanah_2',
|
||||
'luas_bangunan',
|
||||
'nilai_bangunan_1',
|
||||
'nilai_bangunan_2',
|
||||
'total_nilai_pasar_wajar',
|
||||
'likuidasi',
|
||||
'likuidasi_nilai_1',
|
||||
'likuidasi_nilai_2',
|
||||
'asuransi_luas_bangunan',
|
||||
'asuransi_nilai_1',
|
||||
'asuransi_nilai_2',
|
||||
'npw_tambahan'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
// Penanganan khusus untuk field yang boleh null
|
||||
if (in_array($field, ['sarana_pelengkap_penilai', 'nilai_sarana_pelengkap_1', 'nilai_sarana_pelengkap_2'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi khusus untuk npw_tambahan
|
||||
if ($field === 'npw_tambahan' && is_array($data[$field])) {
|
||||
foreach ($data[$field] as $index => $item) {
|
||||
$requiredKeys = ['name', 'luas', 'nilai_1', 'nilai_2'];
|
||||
foreach ($requiredKeys as $key) {
|
||||
if (!isset($item[$key])) {
|
||||
$missingFields[] = "npw_tambahan[$index].$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data LPJ terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data LPJ valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataRap($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->rap, true) ?? [];
|
||||
|
||||
$requiredFields = [
|
||||
'dari',
|
||||
'kepada',
|
||||
'perihal',
|
||||
'tanggal',
|
||||
'nomor_rap'
|
||||
];
|
||||
|
||||
// Cek apakah ada field yang kosong
|
||||
$missingFields = [];
|
||||
foreach ($requiredFields as $field) {
|
||||
if (!isset($data[$field]) || empty($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data RAP terlebih dahulu.",
|
||||
'missing_fields' => $missingFields
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Jika semua data terisi
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data RAP valid."
|
||||
]);
|
||||
}
|
||||
private function getPermohonanJaminanId($id, $dokumentId, $jaminanId)
|
||||
{
|
||||
return Permohonan::with([
|
||||
'user',
|
||||
'debiture.province',
|
||||
'debiture.city',
|
||||
'debiture.district',
|
||||
'debiture.village',
|
||||
'branch',
|
||||
'tujuanPenilaian',
|
||||
'penilaian',
|
||||
'penawaran',
|
||||
'debiture.documents' => function ($query) use ($dokumentId, $jaminanId) {
|
||||
$query->where('id', $dokumentId)
|
||||
->where('jenis_jaminan_id', $jaminanId);
|
||||
}
|
||||
])->findOrFail($id);
|
||||
}
|
||||
|
||||
public function getCommonData()
|
||||
{
|
||||
return [
|
||||
'branches' => Branch::all(),
|
||||
'bentukTanah' => BentukTanah::all(),
|
||||
'konturTanah' => KonturTanah::all(),
|
||||
'posisiKavling' => PosisiKavling::all(),
|
||||
'ketinggianTanah' => KetinggianTanah::all(),
|
||||
'kondisiFisikTanah' => KondisiFisikTanah::all(),
|
||||
'jenisBangunan' => JenisBangunan::all(),
|
||||
'kondisiBangunan' => KondisiBangunan::all(),
|
||||
'sifatBangunan' => SifatBangunan::all(),
|
||||
'spekKategoriBangunan' => SpekKategoritBangunan::all(),
|
||||
'spekBangunan' => SpekBangunan::all(),
|
||||
'saranaPelengkap' => SaranaPelengkap::all(),
|
||||
'arahMataAngin' => ArahMataAngin::all(),
|
||||
'lantai' => Lantai::all(),
|
||||
'viewUnit' => ViewUnit::all(),
|
||||
'golMasySekitar' => GolonganMasySekitar::all(),
|
||||
'tingkatKeramaian' => TingkatKeramaian::all(),
|
||||
'laluLintasLokasi' => LaluLintasLokasi::all(),
|
||||
'jenisPesawat' => JenisPesawat::all(),
|
||||
'modelAlatBerat' => ModelAlatBerat::all(),
|
||||
'jenisKapal' => JenisKapal::all(),
|
||||
'jenisKendaraan' => JenisKendaraan::all(),
|
||||
'terletakArea' => TerletakArea::all(),
|
||||
'posisiUnit' => PosisiUnit::all(),
|
||||
'bentukUnit' => BentukUnit::all(),
|
||||
'fasilitasObjek' => FasilitasObjek::all(),
|
||||
'merupakanDaerah' => MerupakanDaerah::all(),
|
||||
'jenisUnit' => JenisUnit::all(),
|
||||
'jenisJaminan' => JenisJaminan::all(),
|
||||
'hubCadeb' => HubunganPemilikJaminan::all(),
|
||||
'hubPenghuni' => HubunganPenghuniJaminan::all(),
|
||||
'perkerasanJalan' => PerkerasanJalan::all(),
|
||||
'terletakDiArea' => TerletakArea::all(),
|
||||
'tujuanPenilaian' => TujuanPenilaian::all(),
|
||||
'perizinan' => Perizinan::all(),
|
||||
'foto' => FotoObjekJaminan::all()
|
||||
];
|
||||
}
|
||||
|
||||
private const HEADERS = [
|
||||
'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah'],
|
||||
'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah'],
|
||||
'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling'],
|
||||
'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah'],
|
||||
'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah'],
|
||||
'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan'],
|
||||
'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan'],
|
||||
'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan'],
|
||||
'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap'],
|
||||
'lalu-lintas-lokasi' => ['Lalu Lintas Depan Lokasi', 'lalu-lintas-lokasi'],
|
||||
'tingkat-keramaian' => ['Tingkat Keramaian', 'tingkat-keramaian'],
|
||||
'gol-mas-sekitar' => ['Golongan Masyarakat Sekitar', 'gol-mas-sekitar'],
|
||||
'spek-kategori-bangunan' => ['Spek Kategori Bangunan', 'spek-kategori-bangunan'],
|
||||
'spek-bangunan' => ['Spek Bangunan', 'spek-bangunan'],
|
||||
'lantai-unit' => ['Lantai Unit', 'lantai-unit'],
|
||||
'view-unit' => ['View Unit', 'view-unit'],
|
||||
'perkerasan-jalan' => ['Perkerasan jalan', 'perkerasan-jalan'],
|
||||
'jenis-pesawat' => ['Jenis pesawat', 'jenis-pesawat'],
|
||||
'model-alat-berat' => ['Model alat berat', 'model-alat-berat'],
|
||||
'jenis-kapal' => ['Jenis kapal', 'jenis-kapal'],
|
||||
'jenis-kendaraan' => ['Jenis kendaraan', 'jenis-kendaraan'],
|
||||
'jenis-unit' => ['Jenis unit', 'jenis-unit'],
|
||||
'terletak-area' => ['Terletak di Area', 'terletak-area'],
|
||||
'merupakan-daerah' => ['Merupakan Daerah', 'merupakan-daerah'],
|
||||
'posisi-unit' => ['Posisi unit', 'posisi-unit'],
|
||||
'bentuk-unit' => ['Bentuk unit', 'bentuk-unit'],
|
||||
'fasilitas-objek' => ['Fasilitas Umum Dekat Objek', 'fasilitas-objek'],
|
||||
'foto-objek-jaminan' => ['Foto Objek Jaminan', 'foto-objek-jaminan'],
|
||||
'perizinan' => ['Perizinan', 'perizinan'],
|
||||
];
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
class RekapHarianService
|
||||
{
|
||||
public function getRekapHarian()
|
||||
{
|
||||
// return $id;
|
||||
}
|
||||
|
||||
public function totalLaporan()
|
||||
{
|
||||
$jenis_penilaian = JenisPenilaian::all();
|
||||
$laporan = [];
|
||||
$grandTotal = [];
|
||||
|
||||
foreach ($jenis_penilaian as $index => $jenis) {
|
||||
|
||||
$totalLaporanDebiture = $this->totalLaporanDebiture();
|
||||
$totalKunjunganDebiture = $this->totalKunjunganDebiture();
|
||||
$totalKunjunganLokasi = $this->totalKunjunganLokasi();
|
||||
|
||||
|
||||
$grandTotal = [
|
||||
'laporan_debiture' => 0,
|
||||
'debiture' => 0,
|
||||
'lokasi' => 0,
|
||||
'pipeline' => 0
|
||||
];
|
||||
}
|
||||
return $grandTotal;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function totalLaporanDebiture()
|
||||
{
|
||||
$query = [
|
||||
'jenis_penilaian_id' => 1,
|
||||
'total' => 2
|
||||
];
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function totalKunjunganDebiture()
|
||||
{
|
||||
$query = [
|
||||
'jenis_penilaian_id' => 1,
|
||||
'total' => 2
|
||||
];
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function totalKunjunganLokasi()
|
||||
{
|
||||
$query = [
|
||||
'jenis_penilaian_id' => 1,
|
||||
'total' => 2
|
||||
];
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class SaveFormInspesksiService
|
||||
}
|
||||
|
||||
if ($hasFactaData) {
|
||||
$rules = array_merge($rules, $this->getFactData($data, $request, $inspeksi));
|
||||
$rules = array_merge($rules, $this->getFactData($data, $request));
|
||||
}
|
||||
|
||||
return $rules;
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
class TypeLaporanService
|
||||
{
|
||||
public function handleRequest($type, $permohonanId, $documentId, $jaminanId, $surveyorController)
|
||||
{
|
||||
$permohonan = $this->getPermohonanData($surveyorController, $permohonanId, $documentId, $jaminanId);
|
||||
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
throw new \Exception('Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$nomorLaporan = $this->generateNomorLaporan($surveyorController, $permohonan, $documentId, $type);
|
||||
$inspeksi = $this->getInspeksi($permohonanId, $documentId);
|
||||
$this->updatePenilai($permohonanId, $documentId, $type);
|
||||
|
||||
$debitur = Debiture::find($permohonan->debiture_id);
|
||||
$forminspeksi = $inspeksi ? json_decode($inspeksi->data_form, true) : null;
|
||||
|
||||
$locationCodes = $this->getAlamatData($debitur, $forminspeksi);
|
||||
$locationData = $this->getLocationData(
|
||||
$locationCodes['provinceCode'],
|
||||
$locationCodes['cityCode'],
|
||||
$locationCodes['districtCode'],
|
||||
$forminspeksi
|
||||
);
|
||||
|
||||
return [
|
||||
'permohonan' => $permohonan,
|
||||
'nomorLaporan' => $nomorLaporan,
|
||||
'basicData' => $surveyorController->getCommonData(),
|
||||
'cities' => $locationData['cities'],
|
||||
'districts' => $locationData['districts'],
|
||||
'villages' => $locationData['villages'],
|
||||
'forminspeksi' => $forminspeksi,
|
||||
];
|
||||
}
|
||||
|
||||
private function getPermohonanData($surveyorController, $permohonanId, $documentId, $jaminanId)
|
||||
{
|
||||
return $surveyorController->getPermohonanData($permohonanId, $documentId, $jaminanId);
|
||||
}
|
||||
|
||||
private function generateNomorLaporan($surveyorController, $permohonan, $documentId, $type)
|
||||
{
|
||||
return $surveyorController->generateNomorLaporan($permohonan, $documentId, $type);
|
||||
}
|
||||
|
||||
private function getInspeksi($permohonanId, $documentId)
|
||||
{
|
||||
return Inspeksi::where('permohonan_id', $permohonanId)
|
||||
->where('document_id', $documentId)
|
||||
->first();
|
||||
}
|
||||
|
||||
private function updatePenilai($permohonanId, $documentId, $type)
|
||||
{
|
||||
// Logika untuk memperbarui data berdasarkan tipe laporan
|
||||
}
|
||||
|
||||
private function getAlamatData($debitur, $forminspeksi)
|
||||
{
|
||||
return [
|
||||
'provinceCode' => $debitur->province_id ?? $forminspeksi['province'],
|
||||
'cityCode' => $debitur->city_id ?? $forminspeksi['city'],
|
||||
'districtCode' => $debitur->district_id ?? $forminspeksi['district'],
|
||||
];
|
||||
}
|
||||
|
||||
private function getLocationData($provinceCode, $cityCode, $districtCode, $forminspeksi)
|
||||
{
|
||||
return [
|
||||
'cities' => $this->fetchCityData($provinceCode),
|
||||
'districts' => $this->fetchDistrictData($cityCode),
|
||||
'villages' => $this->fetchVillageData($districtCode),
|
||||
];
|
||||
}
|
||||
|
||||
private function fetchCityData($provinceCode)
|
||||
{
|
||||
return City::where('province_code', $provinceCode)->get();
|
||||
}
|
||||
private function fetchDistrictData($cityCode)
|
||||
{
|
||||
return District::where('city_code', $cityCode)->get();
|
||||
}
|
||||
private function fetchVillageData($districtCode)
|
||||
{
|
||||
return Village::where('district_code', $districtCode)->get();
|
||||
}
|
||||
|
||||
private function updateOrCreatePenilai($permohonan_id, $document_id, $type, $data)
|
||||
{
|
||||
return Penilai::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $permohonan_id,
|
||||
'dokument_id' => $document_id,
|
||||
|
||||
],
|
||||
[
|
||||
$type => json_encode($data),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Lpj\Models\JenisLampiran;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('lampiran_dokumen', function (Blueprint $table) {
|
||||
$table->foreignIdFor(JenisLampiran::class)->constrained('jenis_lampiran')->onDelete('cascade')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('lampiran_dokumen', function (Blueprint $table) {
|
||||
$table->dropForeign(['jenis_lampiran_id']);
|
||||
$table->dropColumn('jenis_lampiran_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
@@ -12,16 +13,27 @@ return new class () extends Migration {
|
||||
{
|
||||
Schema::table('debitures', function (Blueprint $table) {
|
||||
// nullable
|
||||
$table->string('cif', 16)
|
||||
->nullable()
|
||||
->default('0000000000')
|
||||
->comment('asal data LPJ.PRM_DEBITUR.KODE_CIF. Pada KODE_CIF ada yang digitnya 16 => 3372040405810002')
|
||||
->change();
|
||||
$table->unsignedBigInteger('branch_id')->nullable()->change();
|
||||
$table->string('cif', 16)->nullable()->comment('asal data LPJ.PRM_DEBITUR.KODE_CIF. Pada KODE_CIF ada yang digitnya 16 => 3372040405810002')->change();
|
||||
$table->string('nomor_id', 50)->nullable()->change();
|
||||
|
||||
// Menambahkan kolom baru dengan nullable dan comment
|
||||
$table->char('mig_addr_display', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.ADDR_DISPLAY');
|
||||
$table->char('mig_comm_display', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.COMM_DISPLAY');
|
||||
$table->char('mig_flag_oto', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR.FLAG_OTO');
|
||||
$table->string('mig_kd_cabang', 11)->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_CABANG. Berguna untuk update branch_id');
|
||||
$table->string('mig_kd_cabang_addr', 11)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.KD_CABANG');
|
||||
$table->string('mig_kd_cabang_comm', 11)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.KD_CABANG');
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_DEBITUR_SEQ. Berguna untuk update debitur_id menggunakan KD_DEBITUR_SEQ nya');
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->string('mig_nama_daerah', 200)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.NAMA_DAERAH');
|
||||
$table->string('mig_no_cif', 20)->nullable()->comment('asal data LPJ.PRM_DEBITUR.NO_CIF');
|
||||
$table->string('mig_nomor_id2', 50)->nullable()->comment('asal data LPJ.PRM_DEBITUR.NO_ID. dipisahkan karena isinya tidak murni number');
|
||||
$table->string('mig_phone', 300)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.COMM_VALUE. dipisahkan karena isinya tidak murni number phone');
|
||||
$table->dateTime('mig_tgl_oto')->nullable()->comment('asal data LPJ.PRM_DEBITUR.TGL_OTO');
|
||||
$table->unsignedBigInteger('mig_urut_seq_addr')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.URUT_SEQ');
|
||||
$table->unsignedBigInteger('mig_urut_seq_comm')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.URUT_SEQ');
|
||||
$table->string('mig_user_oto', 10)->nullable()->comment('asal data LPJ.PRM_DEBITUR.USER_OTO');
|
||||
$table->string('mig_user_update')->nullable()->comment('asal data LPJ.PRM_DEBITUR.USER_UPDATE');
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
@@ -41,10 +53,22 @@ return new class () extends Migration {
|
||||
|
||||
// Hapus kolom tambahan yang dibuat di up()
|
||||
$table->dropColumn([
|
||||
'mig_addr_display',
|
||||
'mig_comm_display',
|
||||
'mig_flag_oto',
|
||||
'mig_kd_cabang',
|
||||
'mig_kd_cabang_addr',
|
||||
'mig_kd_cabang_comm',
|
||||
'mig_kd_debitur_seq',
|
||||
'mig_nama_daerah',
|
||||
'mig_no_cif',
|
||||
'mig_nomor_id2',
|
||||
'mig_phone',
|
||||
'mig_tgl_oto',
|
||||
'mig_urut_seq_addr',
|
||||
'mig_urut_seq_comm',
|
||||
'processed_at',
|
||||
'mig_user_oto',
|
||||
'mig_user_update',
|
||||
'is_mig'
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('mig_debitures_addrs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.KD_DEBITUR_SEQ');
|
||||
$table->unsignedBigInteger('mig_urut_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.URUT_SEQ');
|
||||
$table->unsignedBigInteger('mig_addr_type_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.ADDR_TYPE_SEQ');
|
||||
$table->string('mig_addr_value', 500)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.ADDR_VALUE');
|
||||
$table->string('mig_user_update', 10)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.USER_UPDATE');
|
||||
$table->dateTime('mig_tgl_update')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.TGL_UPDATE');
|
||||
$table->char('mig_flag_oto', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.FLAG_OTO');
|
||||
$table->string('mig_user_oto', 10)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.USER_OTO');
|
||||
$table->dateTime('mig_tgl_oto')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.TGL_OTO');
|
||||
$table->unsignedBigInteger('mig_kd_kel_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.KD_KEL_SEQ');
|
||||
$table->char('mig_addr_display', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.ADDR_DISPLAY');
|
||||
$table->string('mig_kd_cabang', 11)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.KD_CABANG');
|
||||
$table->string('mig_nama_daerah', 200)->nullable()->comment('asal data LPJ.PRM_DEBITUR_ADDR.NAMA_DAERAH');
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('mig_debitures_addrs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('mig_debitures_comms', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.KD_DEBITUR_SEQ');
|
||||
$table->unsignedBigInteger('mig_urut_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.URUT_SEQ');
|
||||
$table->unsignedBigInteger('mig_comm_type_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.COMM_TYPE_SEQ');
|
||||
$table->string('mig_comm_value', 300)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.COMM_VALUE');
|
||||
$table->unsignedBigInteger('mig_addr_type_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.ADDR_TYPE_SEQ');
|
||||
$table->string('mig_user_update', 10)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.USER_UPDATE');
|
||||
$table->dateTime('mig_tgl_update')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.TGL_UPDATE');
|
||||
$table->char('mig_flag_oto', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.FLAG_OTO');
|
||||
$table->string('mig_user_oto', 10)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.USER_OTO');
|
||||
$table->dateTime('mig_tgl_oto')->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.TGL_OTO');
|
||||
$table->char('mig_comm_display', 1)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.ADDR_DISPLAY');
|
||||
$table->string('mig_kd_cabang', 11)->nullable()->comment('asal data LPJ.PRM_DEBITUR_COMM.KD_CABANG');
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('mig_debitures_comms');
|
||||
}
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('permohonan', function (Blueprint $table) {
|
||||
// nullable
|
||||
$table->unsignedBigInteger('branch_id')->nullable()->change();
|
||||
$table->unsignedBigInteger('user_id')->nullable()->change();
|
||||
|
||||
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_DEBITUR_SEQ. Berguna untuk update debitur_id menggunakan KD_DEBITUR_SEQ nya');
|
||||
$table->unsignedBigInteger('nomor_lpj')->nullable();
|
||||
$table->string('mig_nama_ao')->nullable();
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('permohonan', function (Blueprint $table) {
|
||||
// Kembalikan kolom branch_id agar tidak nullable (asumsi awal NOT NULL)
|
||||
$table->unsignedBigInteger('branch_id')->nullable(false)->change();
|
||||
$table->unsignedBigInteger('user_id')->nullable(false)->change();
|
||||
|
||||
|
||||
|
||||
// Hapus kolom tambahan yang dibuat di up()
|
||||
$table->dropColumn([
|
||||
'mig_kd_debitur_seq',
|
||||
'nomor_lpj',
|
||||
'mig_nama_ao',
|
||||
'is_mig'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('dokumen_jaminan', function (Blueprint $table) {
|
||||
// nullable
|
||||
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_DEBITUR_SEQ. Berguna untuk update debitur_id menggunakan KD_DEBITUR_SEQ nya');
|
||||
$table->unsignedBigInteger('nomor_lpj')->nullable();
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('dokumen_jaminan', function (Blueprint $table) {
|
||||
|
||||
|
||||
// Hapus kolom tambahan yang dibuat di up()
|
||||
$table->dropColumn([
|
||||
'nomor_lpj',
|
||||
'mig_kd_debitur_seq',
|
||||
'processed_at',
|
||||
'is_mig'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('pemilik_jaminan', function (Blueprint $table) {
|
||||
// nullable
|
||||
|
||||
$table->unsignedBigInteger('mig_kd_debitur_seq')->nullable()->comment('asal data LPJ.PRM_DEBITUR.KD_DEBITUR_SEQ. Berguna untuk update debitur_id menggunakan KD_DEBITUR_SEQ nya');
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pemilik_jaminan', function (Blueprint $table) {
|
||||
|
||||
|
||||
// Hapus kolom tambahan yang dibuat di up()
|
||||
$table->dropColumn([
|
||||
'mig_kd_debitur_seq',
|
||||
'processed_at',
|
||||
'is_mig'
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('inspeksi', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('nomor_lpj')->nullable();
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('inspeksi', function (Blueprint $table) {
|
||||
$table->dropColumn('nomor_lpj');
|
||||
$table->dropColumn('processed_at');
|
||||
$table->dropColumn('is_mig');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('penilai', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('nomor_lpj')->nullable();
|
||||
$table->timestamp('processed_at')->nullable();
|
||||
$table->char('is_mig', 1)->nullable()->comment('untuk menandakan row ini dari LPJ OLD');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('penilai', function (Blueprint $table) {
|
||||
$table->dropColumn('nomor_lpj');
|
||||
$table->dropColumn('processed_at');
|
||||
$table->dropColumn('is_mig');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Modules\Lpj\Models\DetailDokumenJaminan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DetailDokumenJaminan::query()
|
||||
->whereNotNull('details')
|
||||
->where('details', '!=', '')
|
||||
->where('details', 'not like', '[%]')
|
||||
->update([
|
||||
'details' => DB::raw("CONCAT('[', details, ']')")
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
DetailDokumenJaminan::query()
|
||||
->whereNotNull('details')
|
||||
->where('details', '!=', '')
|
||||
->where('details', 'like', '[%]')
|
||||
->where('details', 'like', '%]')
|
||||
->update([
|
||||
'details' => DB::raw("SUBSTRING(details, 2, LENGTH(details) - 2)")
|
||||
]);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('permohonan', function (Blueprint $table) {
|
||||
$table->string('mig_mst_lpj_nomor_jaminan')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('permohonan', function (Blueprint $table) {
|
||||
$table->dropColumn('mig_mst_lpj_nomor_jaminan');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('persetujuan_penawaran', function (Blueprint $table) {
|
||||
$table->string('nomor_registrasi')->nullable()->after('penawaran_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('persetujuan_penawaran', function (Blueprint $table) {
|
||||
$table->dropColumn('nomor_registrasi');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('category_daftar_pustaka', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code')->unique()->index();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
$table->timestamp('authorized_at')->nullable();
|
||||
$table->char('authorized_status', 1)->nullable();
|
||||
$table->softDeletes();
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->unsignedBigInteger('updated_by')->nullable();
|
||||
$table->unsignedBigInteger('deleted_by')->nullable();
|
||||
$table->unsignedBigInteger('authorized_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('category_daftar_pustaka');
|
||||
}
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('daftar_pustaka', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('judul');
|
||||
$table->string('attachment')->nullable();
|
||||
$table->text('deskripsi');
|
||||
$table->unsignedBigInteger('category_id');
|
||||
$table->foreign('category_id')->references('id')->on('category_daftar_pustaka');
|
||||
$table->timestamps();
|
||||
$table->timestamp('authorized_at')->nullable();
|
||||
$table->char('authorized_status', 1)->nullable();
|
||||
$table->softDeletes();
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->unsignedBigInteger('updated_by')->nullable();
|
||||
$table->unsignedBigInteger('deleted_by')->nullable();
|
||||
$table->unsignedBigInteger('authorized_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('daftar_pustaka');
|
||||
}
|
||||
};
|
||||
@@ -13,25 +13,24 @@ class HubunganPemilikJaminanSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
$hubungan_pemilik_jaminan = [
|
||||
['name' => 'Milik Pribadi'],
|
||||
['name' => 'Suami'],
|
||||
['name' => 'Anak'],
|
||||
['name' => 'Saudara'],
|
||||
['name' => 'Ayah'],
|
||||
['name' => 'Ibu'],
|
||||
['name' => 'Nenek'],
|
||||
['name' => 'Penjual/Developer'],
|
||||
[ 'name' => 'Kakak/adik kandung'],
|
||||
[ 'name' => 'Orang tua'],
|
||||
[ 'name' => 'Mitra Usaha'],
|
||||
[ 'name' => 'Pihak lain'],
|
||||
[ 'name' => 'Negara'],
|
||||
[ 'name' => 'Nenek/kakek'],
|
||||
[ 'name' => 'Milik Keluarga'],
|
||||
[ 'name' => 'Kakak/adik Orangtua'],
|
||||
[ 'name' => 'Istri'],
|
||||
[ 'name' => 'Pengurus'],
|
||||
[ 'name' => 'Lain - lain'],
|
||||
[
|
||||
'name' => 'Milik Pribadi'
|
||||
],
|
||||
[
|
||||
'name' => 'Suami/Istri'
|
||||
],
|
||||
[
|
||||
'name' => 'Anak'
|
||||
],
|
||||
[
|
||||
'name' => 'Saudara Kandung'
|
||||
],
|
||||
[
|
||||
'name' => 'Ayah'
|
||||
],
|
||||
[
|
||||
'name' => 'Ibu'
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($hubungan_pemilik_jaminan as $hpj) {
|
||||
|
||||
@@ -69,49 +69,6 @@ class JenisFasilitasKreditSeeder extends Seeder
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK009',
|
||||
'name' => 'UMKM',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK010',
|
||||
'name' => 'KORPORASI',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK011',
|
||||
'name' => 'KPR 2',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK012',
|
||||
'name' => 'KONSUMER',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK013',
|
||||
'name' => 'KOMERSIL',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'JFK014',
|
||||
'name' => 'KPR REGULER',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,50 +12,36 @@ class LpjDatabaseSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
|
||||
// BranchSeeder::class,
|
||||
// CurrencySeeder::class,
|
||||
// HolidayCalendarSeeder::class,
|
||||
// JenisFasilitasKreditSeeder::class,
|
||||
// JenisLegalitasJaminanSeeder::class,
|
||||
// JenisJaminanSeeder::class,
|
||||
// JenisDokumenSeeder::class,
|
||||
// TujuanPenilaianSeeder::class,
|
||||
// NilaiPlatformSeeder::class,
|
||||
// HubunganPemilikJaminanSeeder::class,
|
||||
// HubunganPenghuniJaminanSeeder::class,
|
||||
// ArahMataAnginSeeder::class,
|
||||
// StatusPermohonanSeeder::class,
|
||||
// RegionSeeder::class,
|
||||
// TeamsSeeder::class,
|
||||
// TeamUsersSeeder::class,
|
||||
// MasterDataSurveyorSeeder::class
|
||||
// JenisPenilaianSeeder::class,
|
||||
// IjinUsahaSeeder::class,
|
||||
// TujuanPenilaianKJPPSeeder::class,
|
||||
// KJPPSeeder::class,
|
||||
// JenisLaporanSeeder::class,
|
||||
// DebitureSeeder::class,
|
||||
// PemilikJaminanSeeder::class,
|
||||
// DokumenJaminanSeeder::class,
|
||||
// DetailDokumenJaminanSeeder::class,
|
||||
// PermohonanSeeder::class,
|
||||
// FotoObjekJaminanSeeder::class,
|
||||
BranchSeeder::class,
|
||||
CurrencySeeder::class,
|
||||
HolidayCalendarSeeder::class,
|
||||
JenisFasilitasKreditSeeder::class,
|
||||
JenisLegalitasJaminanSeeder::class,
|
||||
JenisJaminanSeeder::class,
|
||||
JenisDokumenSeeder::class,
|
||||
TujuanPenilaianSeeder::class,
|
||||
NilaiPlatformSeeder::class,
|
||||
HubunganPemilikJaminanSeeder::class,
|
||||
HubunganPenghuniJaminanSeeder::class,
|
||||
ArahMataAnginSeeder::class,
|
||||
StatusPermohonanSeeder::class,
|
||||
RegionSeeder::class,
|
||||
TeamsSeeder::class,
|
||||
TeamUsersSeeder::class,
|
||||
JenisPenilaianSeeder::class,
|
||||
IjinUsahaSeeder::class,
|
||||
TujuanPenilaianKJPPSeeder::class,
|
||||
KJPPSeeder::class,
|
||||
JenisLaporanSeeder::class,
|
||||
DebitureSeeder::class,
|
||||
PemilikJaminanSeeder::class,
|
||||
DokumenJaminanSeeder::class,
|
||||
DetailDokumenJaminanSeeder::class,
|
||||
PermohonanSeeder::class,
|
||||
FotoObjekJaminanSeeder::class,
|
||||
// PenawaranSeeder::class,
|
||||
// DetailPenawaranSeeder::class,
|
||||
// PenilaianSeeder::class,
|
||||
// MigrationDebitureSeeder::class,
|
||||
// MigrationPermohonanSeeder::class,
|
||||
// MigrationDokumentJaminanSeeder::class,
|
||||
// MigrationDetailDokumenJaminanSeeder::class,
|
||||
// MigPenilaianAndPenilainTeamSeeder::class,
|
||||
// MigrationInpseksiSeeder::class,
|
||||
MigrationGambarInspeksiSeeder::class,
|
||||
// MigrationPembandingSeeder::class,
|
||||
// MigrationPenilaiSeeder::class
|
||||
|
||||
// ini untuk penilaian external
|
||||
// MigExternalPenawaranSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MasterDataSurveyorSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
|
||||
$nameTable = [
|
||||
'fasilitas_objek',
|
||||
'gol_mas_sekitar',
|
||||
'jenis_bangunan',
|
||||
'jenis_kapal',
|
||||
'jenis_kendaraan',
|
||||
'jenis_pesawat',
|
||||
'kondisi_bangunan',
|
||||
'kondisi_fisik_tanah',
|
||||
'kontur_tanah',
|
||||
'lalu_lintas_lokasi',
|
||||
'lantai',
|
||||
'merupakan_daerah',
|
||||
'perkerasan_jalan',
|
||||
'sifat_bangunan',
|
||||
'model_alat_berat',
|
||||
'posisi_kavling',
|
||||
'posisi_unit',
|
||||
'tingkat_keramaian',
|
||||
'sarana_pelengkap',
|
||||
'spek_kategori_bangunan',
|
||||
'spek_bangunan',
|
||||
'terletak_diarea',
|
||||
'view_unit'
|
||||
];
|
||||
|
||||
foreach ($nameTable as $table) {
|
||||
DB::unprepared(file_get_contents(__DIR__ . '/sql/' . $table . '.sql'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigrationLaporanSeeder extends Seeder
|
||||
class MigDebitursAddrsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
@@ -12,5 +13,6 @@ class MigrationLaporanSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::unprepared(file_get_contents(__DIR__ . '/sql/mig_debitures_addrs.sql'));
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PosisiUnitSeeder extends Seeder
|
||||
class MigDebitursCommsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
@@ -12,5 +13,6 @@ class PosisiUnitSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::unprepared(file_get_contents(__DIR__ . '/sql/mig_debitures_comms.sql'));
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SaranaPelengkapSeeder extends Seeder
|
||||
class MigDebitursSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
@@ -12,5 +13,6 @@ class SaranaPelengkapSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::unprepared(file_get_contents(__DIR__ . '/sql/mig_debitures.sql'));
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteAnalisaSeeder.php
Normal file
21
database/seeders/MigDeleteAnalisaSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteAnalisaSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('analisa')->truncate();
|
||||
DB::statement("ALTER TABLE analisa AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteAuthorizationsSeeder.php
Normal file
21
database/seeders/MigDeleteAuthorizationsSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteAuthorizationsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('authorizations')->truncate();
|
||||
DB::statement("ALTER TABLE authorizations AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteDebituresSeeder.php
Normal file
21
database/seeders/MigDeleteDebituresSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteDebituresSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('debitures')->truncate();
|
||||
DB::statement("ALTER TABLE debitures AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteDenahSeeder.php
Normal file
21
database/seeders/MigDeleteDenahSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteDenahSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('denah')->truncate();
|
||||
DB::statement("ALTER TABLE denah AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
22
database/seeders/MigDeleteDetailDokumenJaminanSeeder.php
Normal file
22
database/seeders/MigDeleteDetailDokumenJaminanSeeder.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteDetailDokumenJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('detail_dokumen_jaminan')->truncate();
|
||||
DB::statement("ALTER TABLE detail_dokumen_jaminan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteDokumenJaminanSeeder.php
Normal file
21
database/seeders/MigDeleteDokumenJaminanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteDokumenJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('dokumen_jaminan')->truncate();
|
||||
DB::statement("ALTER TABLE dokumen_jaminan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteFotoJaminanSeeder.php
Normal file
21
database/seeders/MigDeleteFotoJaminanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteFotoJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('foto_jaminan')->truncate();
|
||||
DB::statement("ALTER TABLE foto_jaminan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteInspeksiSeeder.php
Normal file
21
database/seeders/MigDeleteInspeksiSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteInspeksiSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('inspeksi')->truncate();
|
||||
DB::statement("ALTER TABLE inspeksi AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteLampiranDokumenSeeder.php
Normal file
21
database/seeders/MigDeleteLampiranDokumenSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteLampiranDokumenSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('lampiran_dokumen')->truncate();
|
||||
DB::statement("ALTER TABLE lampiran_dokumen AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteLaporanAdminKreditSeeder.php
Normal file
21
database/seeders/MigDeleteLaporanAdminKreditSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteLaporanAdminKreditSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('laporan_admin_kredit')->truncate();
|
||||
DB::statement("ALTER TABLE laporan_admin_kredit AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteLaporanExternalsSeeder.php
Normal file
21
database/seeders/MigDeleteLaporanExternalsSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteLaporanExternalsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('laporan_externals')->truncate();
|
||||
DB::statement("ALTER TABLE laporan_externals AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeleteLaporanSeeder.php
Normal file
21
database/seeders/MigDeleteLaporanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeleteLaporanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('laporan')->truncate();
|
||||
DB::statement("ALTER TABLE laporan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePemilikJaminanSeeder.php
Normal file
21
database/seeders/MigDeletePemilikJaminanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePemilikJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('pemilik_jaminan')->truncate();
|
||||
DB::statement("ALTER TABLE pemilik_jaminan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePenilaiSeeder.php
Normal file
21
database/seeders/MigDeletePenilaiSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePenilaiSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('penilai')->truncate();
|
||||
DB::statement("ALTER TABLE penilai AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePermohonanHistoriesSeeder.php
Normal file
21
database/seeders/MigDeletePermohonanHistoriesSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePermohonanHistoriesSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('permohonan_histories')->truncate();
|
||||
DB::statement("ALTER TABLE permohonan_histories AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePermohonanJaminanSeeder.php
Normal file
21
database/seeders/MigDeletePermohonanJaminanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePermohonanJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('permohonan_jaminan')->truncate();
|
||||
DB::statement("ALTER TABLE permohonan_jaminan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePermohonanPembatalanSeeder.php
Normal file
21
database/seeders/MigDeletePermohonanPembatalanSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePermohonanPembatalanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('permohonan_pembatalan')->truncate();
|
||||
DB::statement("ALTER TABLE permohonan_pembatalan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
23
database/seeders/MigDeletePermohonanSeeder.php
Normal file
23
database/seeders/MigDeletePermohonanSeeder.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePermohonanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('permohonan')->truncate();
|
||||
DB::statement("ALTER TABLE permohonan AUTO_INCREMENT = 1");
|
||||
// DB::table('permohonan')->delete();
|
||||
// DB::statement("ALTER TABLE permohonan AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
21
database/seeders/MigDeletePersetujuanPenawaranSeeder.php
Normal file
21
database/seeders/MigDeletePersetujuanPenawaranSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MigDeletePersetujuanPenawaranSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=0;'); // Nonaktifkan constraint FK sementara
|
||||
DB::table('persetujuan_penawaran')->truncate();
|
||||
DB::statement("ALTER TABLE persetujuan_penawaran AUTO_INCREMENT = 1");
|
||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;'); // Aktifkan kembali FK
|
||||
}
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\PenawaranTender;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\PenilaianTeam;
|
||||
|
||||
class MigExternalPenawaranSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/penawaran/mig_penawaran_external_error.csv';
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Bersihkan/Inisialisasi file error log
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/penawaran/mig_penawaran_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/permohonan/mig_penawaran_external.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500; // Ukuran batch
|
||||
$userDataChace = [];
|
||||
$nomorRegisCahce = [];
|
||||
$errorCount = 0; // Inisialisasi variabel errorCount
|
||||
$errorDebitureIds = []; // Inisialisasi array errorDebitureIds
|
||||
$totalData = 0;
|
||||
|
||||
// Menghitung total data di file CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle); // Reset pointer ke awal file
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
// Jika sudah mencapai batch size, proses batch
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $nomorRegisCahce, $userDataChace, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Proses sisa data jika ada
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $nomorRegisCahce, $userDataChace, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}, Total error: {$errorCount}");
|
||||
}
|
||||
|
||||
|
||||
private function processBatch(
|
||||
array $rows,
|
||||
array &$userDataChace,
|
||||
array &$nomorRegisCahce,
|
||||
int &$errorCount,
|
||||
array &$errorDebitureIds,
|
||||
int $totalData,
|
||||
int $batchCount,
|
||||
int $currentRow
|
||||
) {
|
||||
$userData = [];
|
||||
foreach ($rows as $index => $row) {
|
||||
try {
|
||||
// Jalankan setiap baris dengan transaksi sendiri
|
||||
DB::beginTransaction();
|
||||
|
||||
// Cek apakah sudah diproses
|
||||
$existingRecord = PenawaranTender::where('nomor_registrasi', $row['mig_nomor_jaminan'])->first();
|
||||
if ($existingRecord && $existingRecord->created_at) {
|
||||
$this->command->info('Data sudah diproses sebelumnya: ' . $row['mig_nomor_jaminan']);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil nomor registrasi
|
||||
$nomor_registrasi = $this->getNomorRegistrasiPermohonan($row['mig_nomor_jaminan'], $nomorRegisCahce);
|
||||
if (!$nomor_registrasi) {
|
||||
throw new \Exception("Nomor registrasi tidak valid");
|
||||
}
|
||||
|
||||
|
||||
$userIdUpdate = $this->getUserIdData($row['mig_created_by'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserIdData($row['mig_authorized_by'] ?? null, $userData)['id'];
|
||||
|
||||
if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
// $this->logError($userIdUpdate, 'Salah satu user tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
|
||||
// create random code
|
||||
|
||||
$tgl = $this->parseTimestamp($row['mig_tgl_penyerahan']);
|
||||
|
||||
// ambil nilai tahun terakhir contoh 2023 maka ambil 23
|
||||
$year = date('y', strtotime($tgl));
|
||||
|
||||
// random code berdasarkan tgl contoh NP2300001
|
||||
|
||||
$code = 'NP' . $year . str_pad(rand(1, 99999), 5, '0', STR_PAD_LEFT); // outputnya NP2300001:
|
||||
// Cek apakah kode sudah ada
|
||||
$existingCode = PenawaranTender::where('code', $code)->first();
|
||||
if ($existingCode) {
|
||||
$code = 'NP' . $year . str_pad(rand(1, 99999), 5, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
|
||||
// Buat penilaian
|
||||
$penilaian = PenawaranTender::create([
|
||||
'code' => $code,
|
||||
'nama_kjpp_sebelumnya' => $row['mig_nama_kjpp'],
|
||||
'biaya_kjpp_sebelumnya' => $row['mig_tot_jasa'],
|
||||
'tanggal_penilaian_sebelumnya' => $this->parseTimestamp($row['mig_tgl_penyerahan']),
|
||||
'nomor_registrasi' => $nomor_registrasi,
|
||||
'tujuan_penilaian_kjpp_id' => $this->checkTujuanPenilaian($row['mig_mst_jaminan_kd_tujuan_seq']),
|
||||
'jenis_laporan_id' => 1,
|
||||
'start_date' => $this->parseTimestamp($row['mig_tgl_penyerahan']),
|
||||
'end_date' => $this->parseTimestamp($row['mig_terima_laporan']),
|
||||
'catatan' => $row['mig_catatan'],
|
||||
'status' => 'spk',
|
||||
'created_at' => $this->parseTimestamp($row['mig_created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['mig_updated_at']),
|
||||
'authorized_by' => $mapUser['authorized_by'],
|
||||
'created_by' => $mapUser['created_by'],
|
||||
'updated_by' => $mapUser['updated_by'],
|
||||
]);
|
||||
|
||||
|
||||
|
||||
// Commit transaksi
|
||||
DB::commit();
|
||||
$this->command->info('Proses data penilaian ' . $row['mig_nomor_jaminan'] . ' (' . ($index + 1) . '/' . count($rows) . ')');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Rollback jika ada error
|
||||
DB::rollBack();
|
||||
|
||||
Log::error('Error pada baris: ' . json_encode($row) . '. Pesan: ' . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $row['mig_team_id'] ?? '-';
|
||||
$this->logError($row['mig_team_id'] ?? '-', $e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info("Batch {$batchCount} selesai. Total error: " . count($errorDebitureIds));
|
||||
}
|
||||
|
||||
|
||||
private function getNomorRegistrasiPermohonan($nomor_registrasi_id, $nomorRegisCahce)
|
||||
{
|
||||
if (isset($nomorRegisCahce[$nomor_registrasi_id])) {
|
||||
return $nomorRegisCahce[$nomor_registrasi_id];
|
||||
}
|
||||
|
||||
$nomorRegis = Permohonan::where('nomor_registrasi', $nomor_registrasi_id)->first();
|
||||
|
||||
if (!$nomorRegis) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nomorRegisCahce[$nomor_registrasi_id] = $nomorRegis->nomor_registrasi;
|
||||
return $nomorRegis->nomor_registrasi;
|
||||
}
|
||||
|
||||
private function getUserIdData(?string $code, array &$cache): array
|
||||
{
|
||||
if (!$code) {
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$user = User::where('nik', $code)->first();
|
||||
|
||||
if ($user) {
|
||||
$cache[$code] = ['id' => $user->id, 'branch_id' => $user->branch_id];
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
private function getUserId($mig_user_id, $userDataChace)
|
||||
{
|
||||
if (isset($userDataChace[$mig_user_id])) {
|
||||
return $userDataChace[$mig_user_id];
|
||||
}
|
||||
|
||||
$userId = User::where('nik', $mig_user_id)->first();
|
||||
|
||||
if (!$userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userDataChace[$mig_user_id] = $userId->id;
|
||||
return $userId->id;
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
// Jika file lama ada, hapus
|
||||
if (file_exists($this->errorLogFile)) {
|
||||
unlink($this->errorLogFile);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($this->errorLogFile, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
// Catat ke log
|
||||
Log::error("Error migrasi debiture [$kode]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function checkTujuanPenilaian($code): int
|
||||
{
|
||||
$mapping = [
|
||||
1 => 7,
|
||||
2 => 5,
|
||||
3 => 8,
|
||||
6 => 6,
|
||||
];
|
||||
|
||||
return $mapping[$code] ?? 7;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,313 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
use Modules\Lpj\Models\PenilaianTeam;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
|
||||
class MigPenilaianAndPenilainTeamSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/penilaian/mig_penilaian_and_team_error.csv';
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Bersihkan/Inisialisasi file error log
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/penilaian/mig_penilaian_and_team.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/penilaian/mig_penilaian_and_team.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500; // Ukuran batch
|
||||
$userDataChace = [];
|
||||
$nomorRegisCahce = [];
|
||||
$errorCount = 0; // Inisialisasi variabel errorCount
|
||||
$errorDebitureIds = []; // Inisialisasi array errorDebitureIds
|
||||
$totalData = 0;
|
||||
|
||||
// Menghitung total data di file CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle); // Reset pointer ke awal file
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
// Jika sudah mencapai batch size, proses batch
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $nomorRegisCahce, $userDataChace, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Proses sisa data jika ada
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $nomorRegisCahce, $userDataChace, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}, Total error: {$errorCount}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function processBatch(
|
||||
array $rows,
|
||||
array &$userDataChace,
|
||||
array &$nomorRegisCahce,
|
||||
int &$errorCount,
|
||||
array &$errorDebitureIds,
|
||||
int $totalData,
|
||||
int $batchCount,
|
||||
int $currentRow
|
||||
) {
|
||||
$userData = [];
|
||||
foreach ($rows as $index => $row) {
|
||||
try {
|
||||
// Jalankan setiap baris dengan transaksi sendiri
|
||||
DB::beginTransaction();
|
||||
|
||||
// Cek apakah sudah diproses
|
||||
$existingRecord = Penilaian::where('nomor_registrasi', $row['mig_nomor_registrasi'])->first();
|
||||
if ($existingRecord && $existingRecord->created_at) {
|
||||
$this->command->info('Data sudah diproses sebelumnya: ' . $row['mig_nomor_registrasi']);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil nomor registrasi
|
||||
$nomor_registrasi = $this->getNomorRegistrasiPermohonan($row['mig_nomor_registrasi'], $nomorRegisCahce);
|
||||
if (!$nomor_registrasi) {
|
||||
throw new \Exception("Nomor registrasi tidak valid");
|
||||
}
|
||||
|
||||
// Ambil user ID
|
||||
$userId = $this->getUserId($row['mig_user_id'], $userDataChace);
|
||||
if (!$userId) {
|
||||
// $this->logError($row['mig_user_id'], 'Salah satu user tidak ditemukan');
|
||||
throw new \Exception($row['mig_user_id'] . " User tidak ditemukan");
|
||||
continue;
|
||||
}
|
||||
|
||||
$userIdUpdate = $this->getUserIdData($row['mig_created_by'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserIdData($row['mig_authorized_by'] ?? null, $userData)['id'];
|
||||
|
||||
if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
// $this->logError($userIdUpdate, 'Salah satu user tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
|
||||
// Ambil team ID
|
||||
$teamId = $this->checkTeams($row['mig_team_id']);
|
||||
if (!$teamId) {
|
||||
throw new \Exception("Team tidak ditemukan");
|
||||
}
|
||||
|
||||
// Buat penilaian
|
||||
$penilaian = Penilaian::create([
|
||||
'nomor_registrasi' => $nomor_registrasi,
|
||||
'jenis_penilaian_id' => 1,
|
||||
'tanggal_kunjungan' => $this->parseTimestamp($row['mig_tanggal_kunjungan']) ?? now(),
|
||||
'waktu_penilaian' => $this->parseTimestamp($row['mig_waktu_penilaian']),
|
||||
'status' => 'done',
|
||||
'keterangan' => null,
|
||||
'created_at' => $this->parseTimestamp($row['mig_created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['mig_updated_at']),
|
||||
'authorized_by' => $mapUser['authorized_by'],
|
||||
'created_by' => $mapUser['created_by'],
|
||||
'updated_by' => $mapUser['updated_by'],
|
||||
]);
|
||||
|
||||
// Buat tim penilaian
|
||||
$roles = ['surveyor', 'penilai'];
|
||||
foreach ($roles as $role) {
|
||||
PenilaianTeam::create([
|
||||
'penilaian_id' => $penilaian->id,
|
||||
'user_id' => $userId,
|
||||
'role' => $role,
|
||||
'team_id' => $teamId,
|
||||
'created_at' => $this->parseTimestamp($row['mig_created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['mig_updated_at']),
|
||||
]);
|
||||
}
|
||||
|
||||
// Commit transaksi
|
||||
DB::commit();
|
||||
$this->command->info('Proses data penilaian ' . $row['mig_nomor_lpj'] . ' (' . ($index + 1) . '/' . count($rows) . ')');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Rollback jika ada error
|
||||
DB::rollBack();
|
||||
|
||||
Log::error('Error pada baris: ' . json_encode($row) . '. Pesan: ' . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $row['mig_team_id'] ?? '-';
|
||||
$this->logError($row['mig_team_id'] ?? '-', $e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info("Batch {$batchCount} selesai. Total error: " . count($errorDebitureIds));
|
||||
}
|
||||
|
||||
|
||||
private function getNomorRegistrasiPermohonan($nomor_registrasi_id, $nomorRegisCahce)
|
||||
{
|
||||
if (isset($nomorRegisCahce[$nomor_registrasi_id])) {
|
||||
return $nomorRegisCahce[$nomor_registrasi_id];
|
||||
}
|
||||
|
||||
$nomorRegis = Permohonan::where('nomor_registrasi', $nomor_registrasi_id)->first();
|
||||
|
||||
if (!$nomorRegis) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$nomorRegisCahce[$nomor_registrasi_id] = $nomorRegis->nomor_registrasi;
|
||||
return $nomorRegis->nomor_registrasi;
|
||||
}
|
||||
private function getUserIdData(?string $code, array &$cache): array
|
||||
{
|
||||
if (!$code) {
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$user = User::where('nik', $code)->first();
|
||||
|
||||
if ($user) {
|
||||
$cache[$code] = ['id' => $user->id, 'branch_id' => $user->branch_id];
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
private function getUserId($mig_user_id, $userDataChace)
|
||||
{
|
||||
if (isset($userDataChace[$mig_user_id])) {
|
||||
return $userDataChace[$mig_user_id];
|
||||
}
|
||||
|
||||
$userId = User::where('nik', $mig_user_id)->first();
|
||||
|
||||
if (!$userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$userDataChace[$mig_user_id] = $userId->id;
|
||||
return $userId->id;
|
||||
}
|
||||
|
||||
private function checkTeams($code): int
|
||||
{
|
||||
$mapping = [
|
||||
'01' => 1,
|
||||
'02' => 2,
|
||||
'04' => 4,
|
||||
'07' => 5,
|
||||
'06' => 3,
|
||||
];
|
||||
return $mapping[(string)$code] ?? 1;
|
||||
}
|
||||
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
// Jika file lama ada, hapus
|
||||
if (file_exists($this->errorLogFile)) {
|
||||
unlink($this->errorLogFile);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($this->errorLogFile, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
// Catat ke log
|
||||
Log::error("Error migrasi debiture [$kode]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
|
||||
class MigrationDebitureSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/debitures/error_migration.csv';
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Bersihkan/Inisialisasi file error log
|
||||
$this->initializeErrorLog();
|
||||
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/debitures/mig_debiture.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/debitures/mig_debiture.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500;
|
||||
$userData = [];
|
||||
$branchCache = [];
|
||||
$totalData = 0;
|
||||
|
||||
// Hitung total baris
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Lewati header
|
||||
|
||||
$currentRow = 0;
|
||||
$batchCount = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
$this->logError($data[0] ?? '-', 'Jumlah kolom tidak sesuai');
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}");
|
||||
}
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$userData)
|
||||
{
|
||||
foreach ($rows as $index => $row) {
|
||||
try {
|
||||
$kode = $row['mig_kd_debitur_seq'] ?? '-';
|
||||
|
||||
// Cek apakah sudah diproses sebelumnya
|
||||
$existingRecord = Debiture::where('mig_kd_debitur_seq', $kode)->first();
|
||||
if ($existingRecord && $existingRecord->processed_at) {
|
||||
$this->command->info("Data sudah diproses sebelumnya: $kode");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil branch_id
|
||||
$branchId = $this->getBranchId($row['mig_kd_cabang'] ?? null, $branchCache);
|
||||
if (!$branchId) {
|
||||
$this->logError($kode, 'Cabang tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil user IDs berdasarkan NIK
|
||||
$userIdUpdate = $this->getUserId($row['mig_user_update'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserId($row['mig_user_oto'] ?? null, $userData)['id'];
|
||||
|
||||
// if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
// $this->logError($kode, 'Salah satu user tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
|
||||
// Parsing nomor HP
|
||||
$nomorHp = !empty($row['mig_phone']) ? preg_replace('/[^0-9]/', '', $row['mig_phone']) : null;
|
||||
$email = !empty($row['email']) ? $row['email'] : null;
|
||||
$nomorId = !empty($row['nomor_id']) ? $row['nomor_id'] : null;
|
||||
|
||||
// Parsing waktu
|
||||
$authorizedAt = $this->parseTimestamp($row['mig_tgl_oto'] ?? null);
|
||||
$createdAt = $this->parseTimestamp($row['created_at'] ?? null);
|
||||
$updatedAt = $this->parseTimestamp($row['updated_at'] ?? null);
|
||||
|
||||
if (!$createdAt || !$updatedAt) {
|
||||
$this->logError($kode, 'Gagal parsing created_at / updated_at');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Simpan data
|
||||
Debiture::create([
|
||||
'branch_id' => $branchId,
|
||||
'name' => $row['name'] ?? '',
|
||||
'cif' => $row['cif'] ?: '0000000000',
|
||||
'phone' => $nomorHp,
|
||||
'nomor_id' => $nomorId,
|
||||
'email' => $email,
|
||||
'npwp' => null,
|
||||
'address' => $row['address'] ?? null,
|
||||
'authorized_at' => $authorizedAt,
|
||||
'authorized_by' => $mapUser['authorized_by'],
|
||||
'created_by' => $mapUser['created_by'] ?? null,
|
||||
'updated_by' => $mapUser['updated_by'] ?? null,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $updatedAt,
|
||||
'mig_kd_debitur_seq' => $row['mig_kd_debitur_seq'],
|
||||
'processed_at' => now(),
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
$this->command->info("Proses data debiture $kode (" . ($index + 1) . '/' . count($rows) . ')');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logError($row['mig_kd_debitur_seq'] ?? '-', "Error eksepsi: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getBranchId(?string $code, array &$cache): ?int
|
||||
{
|
||||
if (!$code) return null;
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$branch = Branch::where('code', $code)->first();
|
||||
|
||||
if ($branch) {
|
||||
$cache[$code] = $branch->id;
|
||||
return $branch->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getUserId(?string $code, array &$cache): array
|
||||
{
|
||||
if (!$code) return ['id' => null, 'branch_id' => null];
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$user = User::where('nik', $code)->first();
|
||||
|
||||
if ($user) {
|
||||
$cache[$code] = ['id' => $user->id, 'branch_id' => $user->branch_id];
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
// Jika file lama ada, hapus
|
||||
if (file_exists($this->errorLogFile)) {
|
||||
unlink($this->errorLogFile);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($this->errorLogFile, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
// Catat ke log
|
||||
Log::error("Error migrasi debiture [$kode]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -1,345 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\Village;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\JenisLegalitasJaminan;
|
||||
use Modules\Lpj\Models\PemilikJaminan;
|
||||
use Modules\Lpj\Models\DetailDokumenJaminan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MigrationDetailDokumenJaminanSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/detail-dokumen/mig_detail_dokument_external_error.csv';
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/detail-dokumen/mig_detail_dokument_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/detail-dokumen/mig_detail_dokument_external.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 1000; // Ukuran batch
|
||||
$permohonanCache = [];
|
||||
$jenisJaminanCache = [];
|
||||
$dokumenJaminanCache = [];
|
||||
$provinceCache = [];
|
||||
$cityCache = [];
|
||||
$districtCache = [];
|
||||
$subdistrictCache = [];
|
||||
$totalData = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
$hubunganPemilikCache = [];
|
||||
|
||||
// Menghitung total data di file CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle); // Reset pointer ke awal file
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
|
||||
|
||||
// Membaca setiap baris dalam CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $data[0] ?? 'ID tidak valid'; // Menyimpan ID yang error
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
// print_r($rows);
|
||||
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$errorDebitureIds[] = $data[0] ?? 'ID tidak valid'; // Menyimpan ID yang error
|
||||
$this->processBatch($rows, $permohonanCache, $jenisJaminanCache, $dokumenJaminanCache, $batchCount, $currentRow, $totalData, $errorCount, $errorDebitureIds);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$this->processBatch($rows, $permohonanCache, $jenisJaminanCache, $dokumenJaminanCache, $batchCount, $currentRow, $totalData, $errorCount, $errorDebitureIds);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info('Data debiture berhasil dimigrasikan.');
|
||||
}
|
||||
|
||||
private function processBatch(
|
||||
array $rows,
|
||||
array &$permohonanCache,
|
||||
array &$jenisJaminanCache,
|
||||
array &$dokumenJaminanCache,
|
||||
int $batchCount,
|
||||
int $currentRow,
|
||||
int $totalData,
|
||||
int &$errorCount,
|
||||
array &$errorDebitureIds
|
||||
) {
|
||||
$groupedRows = $this->groupRowsByNomorLaporanAndKeterangan($rows);
|
||||
|
||||
// print_r($groupedRows);
|
||||
|
||||
foreach ($groupedRows as $nomorLaporan => $dataPerGrup) {
|
||||
|
||||
// print_r($dataPerGrup);
|
||||
try {
|
||||
// Ambil salah satu baris untuk referensi (misal baris pertama dari grup)
|
||||
$firstRow = reset($dataPerGrup)['details'] ? reset($dataPerGrup) : reset($dataPerGrup);
|
||||
$debiturId = null;
|
||||
|
||||
// Cari debitur ID dari salah satu field
|
||||
foreach ($rows as $row) {
|
||||
if ($row['mig_nomor_laporan'] == $nomorLaporan) {
|
||||
$debiturId = $row['mig_kd_debitur_seq'] ?? null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$debiturId) {
|
||||
throw new \Exception('Debitur ID tidak ditemukan');
|
||||
}
|
||||
|
||||
// Ambil ID dokumen jaminan
|
||||
$dokumenJaminanId = $this->getDokumenJaminanId($debiturId, $dokumenJaminanCache);
|
||||
if (!$dokumenJaminanId) {
|
||||
throw new \Exception('Dokumen jaminan tidak ditemukan');
|
||||
}
|
||||
|
||||
foreach ($dataPerGrup as $groupKey => $rowData) {
|
||||
// Ambil legalitas jaminan ID berdasarkan grup keterangan
|
||||
$legalitasJaminanId = $this->getLegalitasJaminanId($groupKey, $jenisJaminanCache);
|
||||
if (!$legalitasJaminanId) {
|
||||
throw new \Exception("Legalitas jaminan tidak ditemukan untuk grup: {$groupKey}");
|
||||
}
|
||||
|
||||
// Simpan ke database
|
||||
DetailDokumenJaminan::updateOrCreate(
|
||||
[
|
||||
'name' => $groupKey,
|
||||
'dokumen_jaminan_id' => $dokumenJaminanId,
|
||||
],
|
||||
[
|
||||
'details' => json_encode($rowData['details']),
|
||||
'jenis_legalitas_jaminan_id' => $legalitasJaminanId,
|
||||
'dokumen_jaminan' => !empty($rowData['documents']) ? json_encode($rowData['documents']) : null,
|
||||
'dokumen_nomor' => $nomorLaporan,
|
||||
'keterangan' => $groupKey,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// Info progress
|
||||
$this->command->info("Proses data detail dokumen (Nomor Laporan: {$nomorLaporan}, batch ke: {$batchCount}, total dari: {$currentRow}/{$totalData})");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error pada nomor laporan {$nomorLaporan}: " . $e->getMessage());
|
||||
$this->logError($debiturId ?? '-', $e->getMessage());
|
||||
$errorDebitureIds[] = $debiturId ?? '-';
|
||||
$errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function groupRowsByNomorLaporann(array $rows): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$nomorJaminan = $row['mig_nomor_laporan'] ?? null;
|
||||
if (!empty($nomorJaminan)) {
|
||||
$grouped[$nomorJaminan][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
|
||||
// private function groupRowsByNomorLaporanAndKeterangan(array $rows): array
|
||||
// {
|
||||
// $groupedByNomorLaporan = $this->groupRowsByNomorLaporann($rows);
|
||||
// $finalGrouped = [];
|
||||
|
||||
// foreach ($groupedByNomorLaporan as $nomorLaporan => $rowList) {
|
||||
// $groupedByGrpKeterangan = [];
|
||||
|
||||
// // Urutkan berdasarkan mig_urutan_sub (ascending)
|
||||
// usort($rowList, function ($a, $b) {
|
||||
// return $a['mig_urutan_sub'] <=> $b['mig_urutan_sub'];
|
||||
// });
|
||||
|
||||
// foreach ($rowList as $row) {
|
||||
// $grpKeterangan = $row['mig_grp_keterangan'] ?? 'UNKNOWN_GROUP';
|
||||
|
||||
// if (!isset($groupedByGrpKeterangan[$grpKeterangan])) {
|
||||
// $groupedByGrpKeterangan[$grpKeterangan] = [
|
||||
// 'details' => [],
|
||||
// 'documents' => []
|
||||
// ];
|
||||
// }
|
||||
|
||||
// $keyKeterangan = $row['mig_key_keterangan'] ?? 'UNKNOWN_KEY';
|
||||
// $value = $row['mig_nilai'] ?? null;
|
||||
|
||||
// // Jika belum ada detail, inisialisasi sebagai array asosiatif
|
||||
// if (empty($groupedByGrpKeterangan[$grpKeterangan]['details'])) {
|
||||
// $groupedByGrpKeterangan[$grpKeterangan]['details'][] = [];
|
||||
// }
|
||||
|
||||
// // Masukkan ke dalam object tunggal (bukan item baru)
|
||||
// if ($value !== null) {
|
||||
// $lastIndex = count($groupedByGrpKeterangan[$grpKeterangan]['details']) - 1;
|
||||
// $groupedByGrpKeterangan[$grpKeterangan]['details'][$lastIndex][$keyKeterangan] = $value;
|
||||
// }
|
||||
|
||||
// // Tambahkan dokumen jika ada
|
||||
// $urlFile = $row['mig_url_file'] ?? null;
|
||||
// if (!empty($urlFile)) {
|
||||
// $groupedByGrpKeterangan[$grpKeterangan]['documents'][] = $urlFile;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $finalGrouped[$nomorLaporan] = $groupedByGrpKeterangan;
|
||||
// }
|
||||
|
||||
// // print_r($finalGrouped);
|
||||
// return $finalGrouped;
|
||||
// }
|
||||
|
||||
|
||||
private function groupRowsByNomorLaporanAndKeterangan(array $rows): array
|
||||
{
|
||||
$groupedByNomorLaporan = $this->groupRowsByNomorLaporann($rows);
|
||||
$finalGrouped = [];
|
||||
|
||||
foreach ($groupedByNomorLaporan as $nomorLaporan => $rowList) {
|
||||
$groupedByGrpKeterangan = [];
|
||||
|
||||
// Urutkan berdasarkan mig_urutan_sub
|
||||
usort($rowList, function ($a, $b) {
|
||||
return $a['mig_urutan_sub'] <=> $b['mig_urutan_sub'];
|
||||
});
|
||||
|
||||
foreach ($rowList as $row) {
|
||||
$grpKeterangan = $row['mig_grp_keterangan'] ?? 'UNKNOWN_GROUP';
|
||||
$keyKeterangan = $row['mig_key_keterangan'] ?? 'UNKNOWN_KEY';
|
||||
$value = $row['mig_nilai'] ?? null;
|
||||
|
||||
if (!isset($groupedByGrpKeterangan[$grpKeterangan])) {
|
||||
$groupedByGrpKeterangan[$grpKeterangan] = [
|
||||
'details' => [],
|
||||
'documents' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Masukkan sebagai object baru ke dalam details
|
||||
if ($value !== null) {
|
||||
$groupedByGrpKeterangan[$grpKeterangan]['details'][] = [
|
||||
$keyKeterangan => $value
|
||||
];
|
||||
}
|
||||
|
||||
// Dokumen tetap masuk sebagai array string
|
||||
$urlFile = $row['mig_url_file'] ?? null;
|
||||
if (!empty($urlFile)) {
|
||||
$groupedByGrpKeterangan[$grpKeterangan]['documents'][] = $urlFile;
|
||||
}
|
||||
}
|
||||
|
||||
$finalGrouped[$nomorLaporan] = $groupedByGrpKeterangan;
|
||||
}
|
||||
|
||||
return $finalGrouped;
|
||||
}
|
||||
private function getDokumenJaminanId(string $code, array &$dokumenJaminanCache)
|
||||
{
|
||||
if (isset($dokumenJaminanCache[$code])) {
|
||||
return $dokumenJaminanCache[$code];
|
||||
}
|
||||
|
||||
$dokumen = DokumenJaminan::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($dokumen) {
|
||||
$dokumenJaminanCache[$code] = $dokumen->id;
|
||||
return $dokumen->id;
|
||||
}
|
||||
}
|
||||
|
||||
private function getLegalitasJaminanId(string $code, array &$legalitasJaminanCache)
|
||||
{
|
||||
|
||||
if (isset($legalitasJaminanCache[$code])) {
|
||||
return $legalitasJaminanCache[$code];
|
||||
}
|
||||
|
||||
$legalitas = JenisLegalitasJaminan::whereRaw('LOWER(name) = ?', [strtolower($code)])->first();
|
||||
|
||||
if ($legalitas) {
|
||||
$legalitasJaminanCache[$code] = $legalitas->id;
|
||||
return $legalitas->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file); // Hapus file lama
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
Log::error("Error migrasi dokumen jaminan [$kode]: $message");
|
||||
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,441 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\Village;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\PemilikJaminan;
|
||||
use Modules\Lpj\Models\HubunganPemilikJaminan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class MigrationDokumentJaminanSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external_error_log.csv';
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/dokumen-pemilik/mig_pemilik_dan_dokument_external.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 1000; // Ukuran batch
|
||||
$permohonanCache = [];
|
||||
$jenisJaminanCache = [];
|
||||
$pemilikJaminanCache = [];
|
||||
$provinceCache = [];
|
||||
$cityCache = [];
|
||||
$districtCache = [];
|
||||
$subdistrictCache = [];
|
||||
$totalData = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
$hubunganPemilikCache = [];
|
||||
// Menghitung total data di file CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle); // Reset pointer ke awal file
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
|
||||
|
||||
// Membaca setiap baris dalam CSV
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $data[0] ?? 'ID tidak valid'; // Menyimpan ID yang error
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
// print_r($rows);
|
||||
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$errorDebitureIds[] = $data[0] ?? 'ID tidak valid'; // Menyimpan ID yang error
|
||||
$this->processBatch($rows, $permohonanCache, $jenisJaminanCache, $pemilikJaminanCache, $provinceCache, $cityCache, $districtCache, $subdistrictCache, $batchCount, $currentRow, $totalData, $errorCount, $errorDebitureIds, $hubunganPemilikCache);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$this->processBatch($rows, $permohonanCache, $jenisJaminanCache, $pemilikJaminanCache, $provinceCache, $cityCache, $districtCache, $subdistrictCache, $batchCount, $currentRow, $totalData, $errorCount, $errorDebitureIds, $hubunganPemilikCache);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info('Data debiture berhasil dimigrasikan.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Proses batch data.
|
||||
*/
|
||||
|
||||
private function processBatch(
|
||||
array $rows,
|
||||
array &$permohonanCache,
|
||||
array &$jenisJaminanCache,
|
||||
array &$pemilikJaminanCache,
|
||||
array &$provinceCache,
|
||||
array &$cityCache,
|
||||
array &$districtCache,
|
||||
array &$subdistrictCache,
|
||||
int $batchCount,
|
||||
int $currentRow,
|
||||
int $totalData,
|
||||
int &$errorCount,
|
||||
array &$errorDebitureIds,
|
||||
array &$hubunganPemilikCache
|
||||
) {
|
||||
foreach ($rows as $index => $row) {
|
||||
try {
|
||||
// Jalankan transaksi per-baris
|
||||
DB::beginTransaction();
|
||||
|
||||
// Cari permohonan
|
||||
|
||||
$permohonan = Permohonan::where('nomor_registrasi', $row['mig_nomor_jaminan'])->first();
|
||||
|
||||
if (empty($permohonan)) {
|
||||
throw new \Exception('Missing debiture_id' . $row['mig_nomor_jaminan']);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pastikan permohonan_id belum digunakan di dokumen_jaminan
|
||||
$existingDokumen = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
if ($existingDokumen) {
|
||||
throw new \Exception("permohonan_id {$permohonan->id} sudah digunakan di dokumen_jaminan");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil lokasi
|
||||
|
||||
// jika external silahkan matikan ini
|
||||
|
||||
$proviceCode = $this->getProvinceCode($row['mig_province_name'], $provinceCache);
|
||||
$cityCode = $this->getCityCode($row['mig_city_name'], $cityCache);
|
||||
$districtCode = $this->getDistrictCode($row['mig_district_name'], $districtCache);
|
||||
$subdistrict = $this->getSubdistrictCode($row['mig_village_name'], $subdistrictCache, $districtCache);
|
||||
// $hubunganPemilik = $this->getHubunganPemilikJaminanId($row['mig_hubungan_pemilik_jaminan'], $hubunganPemilikCache);
|
||||
|
||||
|
||||
$pemilik_jaminan_name = $this->getDebitureId($row['mig_kd_debitur_seq'], $pemilikJaminanCache);
|
||||
// Buat Pemilik Jaminan
|
||||
$pemilik_jaminan = PemilikJaminan::updateOrCreate([
|
||||
'debiture_id' => $permohonan->debiture_id,
|
||||
'hubungan_pemilik_jaminan_id' => 1,
|
||||
// 'name' => $row['name'],
|
||||
'name' => $pemilik_jaminan_name,
|
||||
'detail_sertifikat' => null,
|
||||
'npwp' => null,
|
||||
'nomor_id' => null,
|
||||
'email' => null,
|
||||
'phone' => null,
|
||||
// jika external silahkan matikan ini
|
||||
'province_code' => $proviceCode,
|
||||
'city_code' => $cityCode,
|
||||
'district_code' => $districtCode,
|
||||
'village_code' => $subdistrict['code'],
|
||||
'postal_code' => $subdistrict['postal_code'],
|
||||
'address' => $row['address'],
|
||||
'created_at' => $this->parseTimestamp($row['created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['updated_at']),
|
||||
'mig_kd_debitur_seq' => $row['mig_kd_debitur_seq'],
|
||||
'processed_at' => now(),
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
// Buat Dokumen Jaminan
|
||||
DokumenJaminan::updateOrCreate([
|
||||
'debiture_id' => $permohonan->debiture_id,
|
||||
'permohonan_id' => $permohonan->id,
|
||||
'jenis_jaminan_id' => $this->getJaminanId($row['mig_jenis_seq']),
|
||||
'pemilik_jaminan_id' => $pemilik_jaminan->id,
|
||||
// jika external silahkan matikan ini
|
||||
// 'province_code' => $proviceCode,
|
||||
// 'city_code' => $cityCode,
|
||||
// 'district_code' => $districtCode,
|
||||
// 'village_code' => $subdistrict['code'],
|
||||
// 'postal_code' => $subdistrict['postal_code'],
|
||||
'address' => $row['address'],
|
||||
'created_at' => $this->parseTimestamp($row['created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['updated_at']),
|
||||
'mig_kd_debitur_seq' => $row['mig_kd_debitur_seq'],
|
||||
'processed_at' => now(),
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
// Commit jika semua sukses
|
||||
DB::commit();
|
||||
$this->command->info("Proses dokumen jaminan: " . $row['mig_kd_debitur_seq'] . "Batch: {$batchCount} Baris: {$currentRow} Total: {$totalData} Error: {$errorCount}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Rollback hanya untuk baris ini
|
||||
DB::rollBack();
|
||||
|
||||
Log::error("Error pada baris: " . json_encode($row) . ". Pesan: " . $e->getMessage());
|
||||
$this->logError($row['mig_kd_debitur_seq'] ?? '-', $e->getMessage());
|
||||
$errorDebitureIds[] = $row['mig_kd_debitur_seq'] ?? '-';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$this->command->info("Batch {$batchCount} selesai. Total error: " . count($errorDebitureIds));
|
||||
}
|
||||
// private function getPermohonanId($code,$cache)
|
||||
// {
|
||||
// if (isset($cache[$code])) {
|
||||
// return $cache[$code];
|
||||
// }
|
||||
|
||||
// $permohonan = Permohonan::where('mig_kd_debitur_seq', $code)->where('nomor_registrasi', $mig_nomor_jaminan)->first();
|
||||
|
||||
// if ($permohonan) {
|
||||
// $cache[$code] = $permohonan;
|
||||
// return $permohonan;
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
private function getJaminanId($code): ?int
|
||||
{
|
||||
$mapping = [
|
||||
7 => 17,
|
||||
8 => 13,
|
||||
6 => 32,
|
||||
1 => 17,
|
||||
2 => 26,
|
||||
3 => 27,
|
||||
4 => 50,
|
||||
5 => 21,
|
||||
138051314724 => 23,
|
||||
138027243057 => 34,
|
||||
138027664224 => 35,
|
||||
138027738489 => 10,
|
||||
138051485796 => 48,
|
||||
138051492883 => 47,
|
||||
138051515419 => 40,
|
||||
138051753311 => 41,
|
||||
138051754843 => 46,
|
||||
138051759078 => 42,
|
||||
138051480538 => 45,
|
||||
123382184742 => 18,
|
||||
138051483711 => 44,
|
||||
991 => 52
|
||||
];
|
||||
|
||||
return $mapping[$code] ?? 17;
|
||||
}
|
||||
|
||||
private function getPemilikJaminanId(string $code, array &$cache): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$jaminan = PemilikJaminan::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($jaminan) {
|
||||
$cache[$code] = $jaminan->id;
|
||||
return $jaminan->id;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function getDebitureId(string $code, array &$cache): ?string
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$debiture = Debiture::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($debiture) {
|
||||
$cache[$code] = $debiture->name;
|
||||
return $debiture->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private function getProvinceCode(string $name, array &$cache): ?string
|
||||
{
|
||||
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$province = Province::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($province) {
|
||||
$cache[$normalizedName] = $province->code;
|
||||
return $province->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getCityCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$city = City::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($city) {
|
||||
$cache[$normalizedName] = $city->code;
|
||||
return $city->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDistrictCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$district = District::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($district) {
|
||||
$cache[$normalizedName] = $district->code;
|
||||
return $district->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getSubdistrictCode(string $name, array &$cache, array &$districtCache): ?array
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
|
||||
// Pastikan cache menyimpan array, bukan hanya kode
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Ambil subdistrict dari database
|
||||
$subdistrict = Village::whereRaw('LOWER(name) = ?', [$normalizedName])->first();
|
||||
|
||||
// Jika ditemukan, simpan ke dalam cache sebagai array lengkap
|
||||
if ($subdistrict) {
|
||||
$cache[$normalizedName] = [
|
||||
'code' => $subdistrict->code,
|
||||
'postal_code' => $subdistrict->postal_code
|
||||
];
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Jika tidak ditemukan, kembalikan null
|
||||
return [
|
||||
'code' => null,
|
||||
'postal_code' => null
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function getHubunganPemilikJaminanId(string $code, array &$cache): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$jaminan = HubunganPemilikJaminan::whereRaw('LOWER(name) = ?', [strtolower($code)])->first();
|
||||
|
||||
if ($jaminan) {
|
||||
$cache[$code] = $jaminan->id;
|
||||
return $jaminan->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mengonversi nilai TIMESTAMP menjadi format datetime yang valid.
|
||||
*/
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file); // Hapus file lama
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
Log::error("Error migrasi dokumen jaminan [$kode]: $message");
|
||||
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use DateTime;
|
||||
|
||||
class MigrationGambarInspeksiSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
protected $errorLogFile = __DIR__ . '/csv/inspeksi/mig_inspeksi_foto_20253_error.csv';
|
||||
/**
|
||||
* Migrasi data gambar inspeksi dari file csv ke tabel inspeksi_gambar
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/inspeksi/mig_inspeksi_foto_20253.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/inspeksi/mig_inspeksi_foto_20253.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500;
|
||||
$userData = [];
|
||||
$branchCache = []; // <-- Gunakan sebagai cache
|
||||
$totalData = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
// info_harga_laporan_202505021522.csv
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}");
|
||||
}
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$userData, int &$errorCount, array &$errorDebitureIds, int $totalData, int $batchCount, int $currentRow)
|
||||
{
|
||||
// Kelompokkan berdasarkan mig_nomor_jaminan
|
||||
$groupedRows = $this->groupRowsByJaminan($rows);
|
||||
|
||||
foreach ($groupedRows as $nomorJaminan => $groupRows) {
|
||||
try {
|
||||
// Ambil informasi permohonan dan dokument_id
|
||||
$nomorRegis = $this->getNomorRegistrasiPermohonan($nomorJaminan, $branchCache);
|
||||
if (!$nomorRegis) {
|
||||
Log::warning("Nomor registrasi tidak ditemukan untuk nomor jaminan: {$nomorJaminan}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorJaminan;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bangun JSON foto_form
|
||||
$fotoJson = $this->checkFoto($groupRows);
|
||||
|
||||
Inspeksi::where('permohonan_id', $nomorRegis['id'])
|
||||
->where('dokument_id', $nomorRegis['dokument_id'])
|
||||
->whereNotNull('data_form')
|
||||
->update([
|
||||
'foto_form' => $fotoJson,
|
||||
'updated_at' => now()
|
||||
]);
|
||||
|
||||
$this->command->info("Berhasil update foto_form untuk nomor jaminan: {$nomorJaminan}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error pada nomor jaminan {$nomorJaminan}: " . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorJaminan;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
private function groupRowsByJaminan(array $rows): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$nomorJaminan = $row['mig_nomor_jaminan'] ?? null;
|
||||
|
||||
if (!empty($nomorJaminan)) {
|
||||
$grouped[$nomorJaminan][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function checkFoto(array $rows)
|
||||
{
|
||||
// Inisialisasi kelompok untuk tiap kategori
|
||||
$kategoriPrioritas = [
|
||||
'PETA LOKASI' => [],
|
||||
'GAMBAR SITUASI / SURAT UKUR' => [],
|
||||
'FOTO JAMINAN' => [],
|
||||
'lainnya' => []
|
||||
];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
// Ambil kolom penting
|
||||
$namaFoto = trim($row['mig_nama_gambar'] ?? '');
|
||||
$pathFoto = trim($row['mig_url_gambar'] ?? '');
|
||||
$kategori = trim($row['mig_kategori'] ?? 'lainnya');
|
||||
$urutan = (int)($row['mig_urutan_gambar'] ?? 999);
|
||||
$tgl = trim($row['mig_tgl'] ?? '');
|
||||
$nomorLpj = trim($row['mig_nomor_laporan'] ?? '');
|
||||
|
||||
if (empty($pathFoto) || empty($tgl)) {
|
||||
continue; // Lewati jika tidak lengkap
|
||||
}
|
||||
|
||||
try {
|
||||
$tanggal = \Carbon\Carbon::createFromFormat('Y-m-d', $tgl);
|
||||
if (!$tanggal) {
|
||||
throw new \Exception("Tanggal tidak valid");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
continue; // Lewati jika tanggal tidak valid
|
||||
}
|
||||
|
||||
$tahun = $tanggal->format('Y');
|
||||
$bulanAngka = $tanggal->format('n');
|
||||
$bulanNama = [
|
||||
1 => 'JANUARI', 2 => 'FEBRUARI', 3 => 'MARET',
|
||||
4 => 'APRIL', 5 => 'MEI', 6 => 'JUNI',
|
||||
7 => 'JULI', 8 => 'AGUSTUS', 9 => 'SEPTEMBER',
|
||||
10 => 'OKTOBER', 11 => 'NOVEMBER', 12 => 'DESEMBER'
|
||||
][(int)$bulanAngka] ?? 'UNKNOWN';
|
||||
|
||||
$tanggalFormat = $tanggal->format('dmY');
|
||||
|
||||
if (empty($namaFoto)) {
|
||||
$namaFoto = basename($pathFoto) ?: 'image.jpg';
|
||||
}
|
||||
|
||||
// Gunakan '/' sebagai separator path
|
||||
$finalPath = "surveyor/{$tahun}/{$bulanNama}/{$tanggalFormat}/{$nomorLpj}/{$pathFoto}";
|
||||
|
||||
$fotoItem = [
|
||||
'urutan' => $urutan,
|
||||
'name' => $namaFoto,
|
||||
'path' => $finalPath,
|
||||
'category' => $kategori,
|
||||
'sub' => null,
|
||||
'description' => '',
|
||||
'created_by' => null,
|
||||
'created_at' => null
|
||||
];
|
||||
|
||||
// Masukkan ke dalam kelompok kategori
|
||||
if (isset($kategoriPrioritas[$kategori])) {
|
||||
$kategoriPrioritas[$kategori][] = $fotoItem;
|
||||
} else {
|
||||
$kategoriPrioritas['lainnya'][] = $fotoItem;
|
||||
}
|
||||
}
|
||||
|
||||
// Urutkan masing-masing kategori berdasarkan urutan
|
||||
foreach ($kategoriPrioritas as &$kelompok) {
|
||||
usort($kelompok, function ($a, $b) {
|
||||
return $a['urutan'] <=> $b['urutan'];
|
||||
});
|
||||
}
|
||||
|
||||
// Gabungkan dengan urutan prioritas: PETA LOKASI -> GAMBAR SITUASI -> FOTO JAMINAN -> lainnya
|
||||
$finalFotos = array_merge(
|
||||
$kategoriPrioritas['PETA LOKASI'],
|
||||
$kategoriPrioritas['GAMBAR SITUASI / SURAT UKUR'],
|
||||
$kategoriPrioritas['FOTO JAMINAN'],
|
||||
$kategoriPrioritas['lainnya']
|
||||
);
|
||||
|
||||
// Hapus indeks 'urutan'
|
||||
$finalFotos = array_map(function ($foto) {
|
||||
unset($foto['urutan']);
|
||||
return $foto;
|
||||
}, $finalFotos);
|
||||
|
||||
return json_encode([
|
||||
'upload_foto' => $finalFotos
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
private function getNomorRegistrasiPermohonan($nomor_jaminan_id, array &$cache)
|
||||
{
|
||||
// Cek apakah sudah ada di cache
|
||||
if (isset($cache[$nomor_jaminan_id])) {
|
||||
return $cache[$nomor_jaminan_id];
|
||||
}
|
||||
|
||||
// Cari di tabel Permohonan berdasarkan nomor registrasi
|
||||
$permohonan = Permohonan::where('nomor_registrasi', $nomor_jaminan_id)->first();
|
||||
|
||||
if (!$permohonan) {
|
||||
// Tidak ditemukan
|
||||
$cache[$nomor_jaminan_id] = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cari dokument jaminan terkait
|
||||
$dokumenJaminan = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
|
||||
// Simpan hasil ke cache
|
||||
$result = [
|
||||
'id' => $permohonan->id,
|
||||
'dokument_id' => $dokumenJaminan ? $dokumenJaminan->id : null
|
||||
];
|
||||
|
||||
$cache[$nomor_jaminan_id] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file); // Hapus file lama
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
Log::error("Error migrasi dokumen jaminan [$kode]: $message");
|
||||
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -1,858 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\Village;
|
||||
|
||||
// Load file helper
|
||||
require_once __DIR__ . '/MigInspeksiHelper.php';
|
||||
class MigrationInpseksiSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/inspeksi/mig_inspeksi_2025_error.csv';
|
||||
// protected $fielKesimpulan = ;
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/inspeksi/mig_inspeksi_2025.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/inspeksi/mig_inspeksi_2025.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500;
|
||||
$userData = [];
|
||||
$branchCache = []; // <-- Gunakan sebagai cache
|
||||
$totalData = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}");
|
||||
}
|
||||
|
||||
|
||||
private function processBatch(
|
||||
array $rows,
|
||||
array &$branchCache,
|
||||
array &$debitureCache,
|
||||
int &$errorCount,
|
||||
array &$errorDebitureIds,
|
||||
int $totalData,
|
||||
int $batchCount,
|
||||
int $currentRow
|
||||
) {
|
||||
// Kelompokkan baris berdasarkan mig_nomor_jaminan
|
||||
$groupedData = $this->groupRowsByJaminan($rows);
|
||||
|
||||
foreach ($groupedData as $nomorJaminan => $groupRows) {
|
||||
try {
|
||||
// Ambil informasi permohonan
|
||||
$nomorRegis = $this->getNomorRegistrasiPermohonan($nomorJaminan, $branchCache);
|
||||
if (!$nomorRegis) {
|
||||
Log::warning("Nomor registrasi tidak ditemukan untuk nomor jaminan: {$nomorJaminan}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorJaminan;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Cek apakah sudah ada data
|
||||
$existingRecord = Inspeksi::where('permohonan_id', $nomorRegis['id'])
|
||||
->where('dokument_id', $nomorRegis['dokument_id'])
|
||||
->whereNotNull('data_form')
|
||||
->first();
|
||||
|
||||
if ($existingRecord) {
|
||||
$this->command->info("Data untuk nomor jaminan {$nomorJaminan} sudah ada. Lewati...");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil baris pertama untuk created_at/updated_at
|
||||
$firstRow = reset($groupRows);
|
||||
|
||||
// Bangun JSON lengkap
|
||||
$dataFormJson = $this->buildFullDataForm($groupRows);
|
||||
$jenisJaminan = $this->checkJenisJaminan($groupRows[0]['mig_name'] ?? '');
|
||||
|
||||
if (!$dataFormJson) {
|
||||
Log::warning("Data form kosong untuk nomor jaminan: {$nomorJaminan}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorJaminan;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Simpan ke database hanya sekali per grup
|
||||
Inspeksi::create([
|
||||
'name' => $jenisJaminan,
|
||||
'data_form' => $dataFormJson,
|
||||
'foto_form' => null,
|
||||
'data_pembanding' => null,
|
||||
'permohonan_id' => $nomorRegis['id'] ?? null,
|
||||
'dokument_id' => $nomorRegis['dokument_id'] ?? null,
|
||||
'created_at' => $this->parseTimestamp($firstRow['created_at'] ?? null),
|
||||
'updated_at' => $this->parseTimestamp($firstRow['updated_at'] ?? null),
|
||||
'nomor_lpj' => $nomorJaminan,
|
||||
'processed_at' => now(),
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
$this->command->info("Berhasil simpan data inspeksi untuk nomor jaminan: {$nomorJaminan}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error pada nomor jaminan {$nomorJaminan}: " . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorJaminan;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
private function groupRowsByJaminan(array $rows): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$nomorJaminan = $row['mig_nomor_jaminan'] ?? null;
|
||||
|
||||
if (!empty($nomorJaminan)) {
|
||||
$grouped[$nomorJaminan][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
private function getNomorRegistrasiPermohonan($nomor_jaminan_id, array &$cache)
|
||||
{
|
||||
// Cek apakah sudah ada di cache
|
||||
if (isset($cache[$nomor_jaminan_id])) {
|
||||
return $cache[$nomor_jaminan_id];
|
||||
}
|
||||
|
||||
// Cari di tabel Permohonan berdasarkan nomor registrasi
|
||||
$permohonan = Permohonan::where('nomor_registrasi', $nomor_jaminan_id)->first();
|
||||
|
||||
if (!$permohonan) {
|
||||
// Tidak ditemukan
|
||||
$cache[$nomor_jaminan_id] = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cari dokument jaminan terkait
|
||||
$dokumenJaminan = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
|
||||
// Simpan hasil ke cache
|
||||
$result = [
|
||||
'id' => $permohonan->id,
|
||||
'dokument_id' => $dokumenJaminan ? $dokumenJaminan->id : null
|
||||
];
|
||||
|
||||
$cache[$nomor_jaminan_id] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function buildFullDataForm(array $rows)
|
||||
{
|
||||
if (empty($rows)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$jenisJaminan = $rows[0]['mig_name'] ?? null;
|
||||
|
||||
if (!$jenisJaminan) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$jsonResult = $this->checkBuildJson($jenisJaminan, $rows);
|
||||
// Validasi apakah hasil JSON valid
|
||||
json_decode($jsonResult);
|
||||
return $jsonResult;
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Gagal build JSON untuk jenis jaminan {$jenisJaminan}: " . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function loadKesimpulanByNomorLpj($nomorLpj)
|
||||
{
|
||||
$filePath = realpath(__DIR__ . '/csv/inspeksi/mig_inspeksi_kesimpulan_2025.csv');
|
||||
|
||||
if (!$filePath || !$nomorLpj) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error("Gagal membuka file CSV kesimpulan: " . $filePath);
|
||||
return [];
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$result = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = array_combine($header, $data);
|
||||
|
||||
if ($row['mig_nomor_lpj'] === $nomorLpj) {
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($result);
|
||||
|
||||
fclose($handle);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkLingkungan($rows)
|
||||
{
|
||||
$dataToInsertJson = [];
|
||||
|
||||
// Inisialisasi struktur lingkungan
|
||||
$lingkungan = [
|
||||
'jarak_jalan_utama' => null,
|
||||
'jalan_linkungan' => null,
|
||||
'jarak_cbd_point' => null,
|
||||
'nama_cbd_point' => null,
|
||||
'lebar_perkerasan_jalan' => null,
|
||||
'perkerasan_jalan' => ['perkerasan_jalan' => [], 'lainnya' => null],
|
||||
'lalu_lintas' => null,
|
||||
'gol_mas_sekitar' => [],
|
||||
'tingkat_keramaian' => [],
|
||||
'terletak_diarea' => ['terletak_diarea' => [], 'lainnya' => null],
|
||||
'disekitar_lokasi' => null,
|
||||
'kondisi_bagunan_disekitar_lokasi' => null,
|
||||
'sifat_bagunan_disekitar_lokasi' => null,
|
||||
'dekat_makam' => 'tidak',
|
||||
'jarak_makam' => null,
|
||||
'nama_makam' => null,
|
||||
'dekat_tps' => 'tidak',
|
||||
'jarak_tps' => null,
|
||||
'nama_tps' => null,
|
||||
'dekat_lainnya' => null,
|
||||
'merupakan_daerah' => [],
|
||||
'fasilitas_dekat_object' => [],
|
||||
'fasilitas_dekat_object_input' => [
|
||||
'Tempat Ibadah' => null,
|
||||
'Rumah Sakit' => null,
|
||||
'Sekolah' => null,
|
||||
'Kantor Pemerintahan' => null,
|
||||
'Stasiun Kereta' => null,
|
||||
'Terminal Bus' => null,
|
||||
'Bandara' => null,
|
||||
'Pos Polisi' => null,
|
||||
'Lainnya' => null
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$name = trim($row['name']);
|
||||
$value = !empty($row['mig_name_keterangan_lain']) ? $row['mig_name_keterangan_lain'] : $row['mig_name_keterangan'];
|
||||
|
||||
switch ($name) {
|
||||
case 'Lebar jalan dimuka lokasi':
|
||||
$lingkungan['lebar_perkerasan_jalan'] = $row['mig_name_keterangan_lain'];
|
||||
break;
|
||||
|
||||
case 'Lapisan perkerasan jalan dari':
|
||||
if ($value === 'Lainnya') {
|
||||
$lingkungan['perkerasan_jalan']['perkerasan_jalan'][] = $value;
|
||||
$lingkungan['perkerasan_jalan']['lainnya'] = $row['mig_name_keterangan_lain'];
|
||||
} else {
|
||||
$lingkungan['perkerasan_jalan']['perkerasan_jalan'][] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Lalulintas didepan lokasi':
|
||||
$lingkungan['lalu_lintas'] = $value;
|
||||
break;
|
||||
|
||||
case 'Golongan Masyarakat sekitar':
|
||||
$lingkungan['gol_mas_sekitar'][] = $value;
|
||||
break;
|
||||
|
||||
case 'Dengan kondisi':
|
||||
$lingkungan['tingkat_keramaian'][] = $value;
|
||||
break;
|
||||
|
||||
case 'Terletak didaerah':
|
||||
if ($value === 'Lainnya') {
|
||||
$lingkungan['terletak_diarea']['terletak_diarea'][] = $value;
|
||||
$lingkungan['terletak_diarea']['lainnya'] = $row['mig_name_keterangan_lain'];
|
||||
} else {
|
||||
$lingkungan['terletak_diarea']['terletak_diarea'][] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Disekitar lokasi':
|
||||
$lingkungan['disekitar_lokasi'] = $value === 'Telah ada bangunan' ? 'sesuai' : 'tidak sesuai';
|
||||
break;
|
||||
|
||||
case 'Merupakan daerah':
|
||||
$lingkungan['merupakan_daerah'][] = $value;
|
||||
break;
|
||||
|
||||
case 'Fasilitas umum dekat lokasi':
|
||||
$lingkungan['fasilitas_dekat_object'][] = $value;
|
||||
if (isset($lingkungan['fasilitas_dekat_object_input'][$value])) {
|
||||
$lingkungan['fasilitas_dekat_object_input'][$value] = $value;
|
||||
} elseif ($value === 'Pasar / Swalayan') {
|
||||
$lingkungan['fasilitas_dekat_object_input']['Lainnya'] = 'pasar';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Isi default jika kosong
|
||||
if (empty($lingkungan['fasilitas_dekat_object'])) {
|
||||
$lingkungan['fasilitas_dekat_object'] = [];
|
||||
}
|
||||
|
||||
// Masukkan ke array JSON
|
||||
$dataToInsertJson[] = json_encode([
|
||||
'lingkungan' => $lingkungan
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return $dataToInsertJson;
|
||||
}
|
||||
|
||||
private function checkAsset(array $rows)
|
||||
{
|
||||
$dataToInsertJson = [];
|
||||
|
||||
// Ambil baris pertama saja
|
||||
$firstRow = reset($rows);
|
||||
|
||||
if (!$firstRow) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Inisialisasi variabel dari baris pertama
|
||||
$hubCadeb = null;
|
||||
$hubPenghuni = null;
|
||||
$jenisAsset = null;
|
||||
|
||||
// Ambil data utama dari baris pertama
|
||||
$pihakBank = $firstRow['mig_pihak_bank'] ?? null;
|
||||
$debiturPerwakilan = $firstRow['mig_debiture_perwakilan'] ?? null;
|
||||
$address = $firstRow['address'] ?? null;
|
||||
|
||||
// Kode wilayah
|
||||
$provinceCache = []; // cache untuk helper
|
||||
$cityCache = [];
|
||||
$districtCache = [];
|
||||
$subdistrictCache = [];
|
||||
|
||||
$proviceCode = $this->getProvinceCode($firstRow['mig_village_name'] ?? '', $provinceCache);
|
||||
$cityCode = $this->getCityCode($firstRow['mig_city_name'] ?? '', $cityCache);
|
||||
$districtCode = $this->getDistrictCode($firstRow['mig_district_name'] ?? '', $districtCache);
|
||||
$subdistrict = $this->getSubdistrictCode($firstRow['mig_province_name'] ?? '', $subdistrictCache, $districtCache);
|
||||
|
||||
// Proses hubungan pemilik/penghuni & jenis asset dari seluruh rows
|
||||
foreach ($rows as $row) {
|
||||
$name = trim($row['name'] ?? '');
|
||||
$keySesuaiORTidak = !empty($row['mig_name_keterangan_lain']) ? 'sesuai' : 'tidak sesuai';
|
||||
$value = !empty($row['mig_name_keterangan_lain'])
|
||||
? $row['mig_name_keterangan_lain']
|
||||
: $row['mig_name_keterangan'] ?? null;
|
||||
|
||||
switch ($name) {
|
||||
case 'Hubungan Pemilik Jaminan dengan Debitur':
|
||||
$hubCadeb = [
|
||||
$keySesuaiORTidak => $value
|
||||
];
|
||||
break;
|
||||
|
||||
case 'Hubungan Penghuni Jaminan dengan Debitur':
|
||||
$hubPenghuni = [
|
||||
$keySesuaiORTidak => $value
|
||||
];
|
||||
break;
|
||||
|
||||
case 'Jenis Bangunan':
|
||||
$jenisAsset = [
|
||||
$keySesuaiORTidak => $value
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Isi default jika kosong
|
||||
if (empty($hubCadeb)) {
|
||||
$hubCadeb = ["tidak sesuai" => null];
|
||||
}
|
||||
if (empty($hubPenghuni)) {
|
||||
$hubPenghuni = ["tidak sesuai" => null];
|
||||
}
|
||||
if (empty($jenisAsset)) {
|
||||
$jenisAsset = ["sesuai" => null];
|
||||
}
|
||||
|
||||
// Bangun struktur JSON
|
||||
$asset = [
|
||||
"debitur_perwakilan" => $debiturPerwakilan,
|
||||
"jenis_asset" => $jenisAsset,
|
||||
"alamat" => [
|
||||
"sesuai" => [
|
||||
"address" => $address,
|
||||
"village_code" => $subdistrict['code'],
|
||||
"district_code" => $districtCode,
|
||||
"city_code" => $cityCode,
|
||||
"province_code" => $proviceCode
|
||||
]
|
||||
],
|
||||
"hub_cadeb" => $hubCadeb,
|
||||
"hub_cadeb_penghuni" => $hubPenghuni,
|
||||
"pihak_bank" => $pihakBank,
|
||||
"kordinat_lng" => null,
|
||||
"kordinat_lat" => null
|
||||
];
|
||||
|
||||
// Masukkan ke array JSON
|
||||
$dataToInsertJson[] = json_encode([
|
||||
"asset" => $asset
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return $dataToInsertJson;
|
||||
}
|
||||
|
||||
|
||||
private function checkKesimpulan($rows)
|
||||
{
|
||||
$dataToInsertJson = [];
|
||||
|
||||
$fakta = [
|
||||
'fakta_positif' => [],
|
||||
'fakta_negatif' => [],
|
||||
'rute_menuju' => null,
|
||||
'batas_batas' => ["Utara", "Timur", "Selatan", "Barat"],
|
||||
'batas_batas_input' => [
|
||||
"Utara" => null,
|
||||
"Timur Laut" => null,
|
||||
"Timur" => null,
|
||||
"Tenggara" => null,
|
||||
"Selatan" => null,
|
||||
"Barat Daya" => null,
|
||||
"Barat" => null,
|
||||
"Barat Laut" => null,
|
||||
"Utara Timur Laut" => null,
|
||||
"Timur Timur Laut" => null,
|
||||
"Timur Tenggara" => null,
|
||||
"Selatan Tenggara" => null,
|
||||
"Selatan Barat Daya" => null,
|
||||
"Barat Barat Daya" => null,
|
||||
"Barat Barat Laut" => null,
|
||||
"Utara Barat Laut" => null
|
||||
],
|
||||
'kondisi_lingkungan' => [],
|
||||
'kondisi_lain_bangunan' => [],
|
||||
'informasi_dokument' => [],
|
||||
'peruntukan' => null,
|
||||
'kdb' => null,
|
||||
'kdh' => null,
|
||||
'gsb' => null,
|
||||
'max_lantai' => null,
|
||||
'klb' => null,
|
||||
'gss' => null,
|
||||
'pelebaran_jalan' => null,
|
||||
'nama_petugas' => null,
|
||||
'keterangan' => [],
|
||||
'saran' => []
|
||||
];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$jenis = trim($row['mig_keterangan']); // misal: Fakta Positif, Fakta Negatif, dll
|
||||
$keterangan = trim($row['mig_kesimpulan']);
|
||||
|
||||
switch ($jenis) {
|
||||
case 'Faktor Positif':
|
||||
$fakta['fakta_positif'][] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'Faktor Negatif':
|
||||
$fakta['fakta_negatif'][] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'Rute Menuju':
|
||||
$fakta['rute_menuju'] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'Kondisi Lingkungan':
|
||||
$fakta['kondisi_lingkungan'][] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'Kondisi Bangunan':
|
||||
$fakta['kondisi_lain_bangunan'][] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'Lain - lain':
|
||||
$fakta['informasi_dokument'][] = $keterangan;
|
||||
break;
|
||||
|
||||
case 'CATATAN YANG PERLU DIPERHATIKAN':
|
||||
$fakta['keterangan'][] = $keterangan;
|
||||
break;
|
||||
case 'Catatan':
|
||||
$fakta['keterangan'][] = $keterangan;
|
||||
break;
|
||||
case 'Saran':
|
||||
$fakta['saran'][] = $keterangan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dataToInsertJson[] = json_encode([
|
||||
'fakta' => $fakta
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return $dataToInsertJson;
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function getProvinceCode(string $name, array &$cache): ?string
|
||||
{
|
||||
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$province = Province::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($province) {
|
||||
$cache[$normalizedName] = $province->code;
|
||||
return $province->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getCityCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$city = City::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($city) {
|
||||
$cache[$normalizedName] = $city->code;
|
||||
return $city->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDistrictCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$district = District::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($district) {
|
||||
$cache[$normalizedName] = $district->code;
|
||||
return $district->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getSubdistrictCode(string $name, array &$cache, array &$districtCache): ?array
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
|
||||
// Pastikan cache menyimpan array, bukan hanya kode
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Ambil subdistrict dari database
|
||||
$subdistrict = Village::whereRaw('LOWER(name) = ?', [$normalizedName])->first();
|
||||
|
||||
// Jika ditemukan, simpan ke dalam cache sebagai array lengkap
|
||||
if ($subdistrict) {
|
||||
$cache[$normalizedName] = [
|
||||
'code' => $subdistrict->code,
|
||||
'postal_code' => $subdistrict->postal_code
|
||||
];
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Jika tidak ditemukan, kembalikan null
|
||||
return [
|
||||
'code' => null,
|
||||
'postal_code' => null
|
||||
];
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
// Hapus file lama jika ada
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_mst_jaminan_nomor_jaminan', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError($nomorJaminan, string $message)
|
||||
{
|
||||
Log::error("Error migrasi permohonan [$nomorJaminan]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$nomorJaminan, $message]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function checkJenisJaminan($input)
|
||||
{
|
||||
$input = trim($input);
|
||||
switch ($input) {
|
||||
case 'Tanah dan Bangunan eks KPR-BPPN':
|
||||
return 'tanah, bangunan, lingkungan, fakta, informasi';
|
||||
case 'Pabrik':
|
||||
return 'tanah, bangunan, lingkungan, fakta, informasi';
|
||||
case 'Kapal Laut':
|
||||
return 'kapal-laut';
|
||||
|
||||
case 'Tanah dan/atau Bangunan':
|
||||
return 'tanah, bangunan';
|
||||
|
||||
case 'Kendaraan Bermotor':
|
||||
return 'kendaraan-';
|
||||
|
||||
case 'Mesin-mesin dan Peralatan':
|
||||
return 'mesin';
|
||||
|
||||
case 'Barang Dagangan/FEO':
|
||||
return 'barang-dagangan';
|
||||
|
||||
case 'Pesawat Udara':
|
||||
return 'pesawat-udara';
|
||||
|
||||
case 'Alat Berat':
|
||||
return 'alat-berat';
|
||||
|
||||
case 'Deposito':
|
||||
return 'deposito';
|
||||
|
||||
case 'Rekening Giro / Tabungan':
|
||||
return 'rekening-giro-tabungan';
|
||||
|
||||
case 'Emas':
|
||||
return 'emas';
|
||||
|
||||
case 'Jaminan Pribadi / Personal Guarantee':
|
||||
return 'jaminan-pribadi';
|
||||
|
||||
case 'Jaminan Perusahaan / Corporate Guarantee':
|
||||
return 'jaminan-perusahaan';
|
||||
|
||||
case 'Resi Gudang':
|
||||
return 'resi-gudang';
|
||||
|
||||
case 'Surat Berharga dan Saham':
|
||||
return 'surat-berharga-saham';
|
||||
|
||||
case 'Tanah dan Bangunan (KerjaSama)':
|
||||
return 'tanah-bangunan-kerja-sama';
|
||||
|
||||
case 'Tanah Kavling (Kerjasama)':
|
||||
return 'tanah-kavling';
|
||||
|
||||
case 'Persediaan Barang / Barang Dagangan':
|
||||
return 'persediaan-barang';
|
||||
|
||||
case 'Apartemen':
|
||||
return 'apartemen';
|
||||
|
||||
case 'Tagihan / Piutang Dagang':
|
||||
return 'tagihan-piutang';
|
||||
|
||||
case 'Tanah dan/atau Bangunan KPR - SEDERHANA':
|
||||
return 'tanah-bangunan-kpr-sederhana';
|
||||
|
||||
default:
|
||||
return 'lainnya';
|
||||
}
|
||||
}
|
||||
|
||||
public function checkBuildJson($input, $rows = [])
|
||||
{
|
||||
$input = trim($input);
|
||||
|
||||
// Pastikan rows selalu array
|
||||
if (!is_array($rows)) {
|
||||
$rows = [$rows];
|
||||
}
|
||||
|
||||
switch ($input) {
|
||||
case 'Tanah dan Bangunan eks KPR-BPPN':
|
||||
case 'Pabrik':
|
||||
case 'Tanah dan/atau Bangunan':
|
||||
case 'Apartemen':
|
||||
case 'Tanah dan/atau Bangunan KPR - SEDERHANA':
|
||||
$assetJson = json_decode($this->checkAsset($rows)[0] ?? '', true);
|
||||
$tanahJson = json_decode(buildInspeksiTanah($rows)[0] ?? '', true);
|
||||
$bangunanJson = json_decode(buildInspeksiBangunan($rows)[0] ?? '', true);
|
||||
$lingkunganJson = json_decode($this->checkLingkungan($rows)[0] ?? '', true);
|
||||
|
||||
$nomorLpj = $rows[0]['mig_nomor_lpj'] ?? null;
|
||||
$kesimpulanRows = $this->loadKesimpulanByNomorLpj($nomorLpj);
|
||||
|
||||
$faktaJson = [];
|
||||
if (!empty($kesimpulanRows)) {
|
||||
$faktaResult = $this->checkKesimpulan($kesimpulanRows);
|
||||
$faktaJson = json_decode($faktaResult[0] ?? '', true)['fakta'] ?? [];
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'asset' => $assetJson['asset'] ?? [],
|
||||
'tanah' => $tanahJson['tanah'] ?? [],
|
||||
'bangunan' => $bangunanJson['bangunan'] ?? [],
|
||||
'lingkungan' => $lingkunganJson['lingkungan'] ?? [],
|
||||
'fakta' => $faktaJson
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Kapal Laut':
|
||||
$kapal = createInspeksiKapal($rows);
|
||||
return json_encode($kapal, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Kendaraan Bermotor':
|
||||
$kendaraan = createInspeksiKendaraan($rows);
|
||||
return json_encode($kendaraan, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Mesin-mesin dan Peralatan':
|
||||
$mesin = createInspeksiMesin($rows);
|
||||
return json_encode($mesin, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Pesawat Udara':
|
||||
$pesawat = createInspeksiPesawat($rows);
|
||||
return json_encode($pesawat, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Alat Berat':
|
||||
$alatBerat = createInspeksiAlatBerat($rows);
|
||||
return json_encode($alatBerat, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
case 'Barang Dagangan/FEO':
|
||||
case 'Deposito':
|
||||
case 'Rekening Giro / Tabungan':
|
||||
case 'Emas':
|
||||
case 'Jaminan Pribadi / Personal Guarantee':
|
||||
case 'Jaminan Perusahaan / Corporate Guarantee':
|
||||
case 'Resi Gudang':
|
||||
case 'Surat Berharga dan Saham':
|
||||
case 'Persediaan Barang / Barang Dagangan':
|
||||
case 'Tagihan / Piutang Dagang':
|
||||
return json_encode([
|
||||
'status' => 'pending',
|
||||
'message' => 'Fungsi untuk "' . $input . '" belum diimplementasikan.',
|
||||
'data' => $rows
|
||||
]);
|
||||
case 'Tanah dan Bangunan (KerjaSama)':
|
||||
case 'Tanah Kavling (Kerjasama)':
|
||||
$pesawat = buildRapJsonData($rows);
|
||||
return json_encode($pesawat, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
default:
|
||||
return json_encode([
|
||||
'status' => 'unknown',
|
||||
'message' => 'Jenis aset tidak dikenali: ' . $input,
|
||||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
|
||||
class MigrationPembandingSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/inspeksi/mig_pembanding_2025_error.csv';
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/inspeksi/mig_pembanding_2025.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/inspeksi/mig_pembanding_2025.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500;
|
||||
$userData = [];
|
||||
$branchCache = []; // <-- Gunakan sebagai cache
|
||||
$totalData = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
// info_harga_laporan_202505021522.csv
|
||||
// print_r($rows[0]);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}");
|
||||
}
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$userData, int &$errorCount, array &$errorDebitureIds, int $totalData, int $batchCount, int $currentRow)
|
||||
{
|
||||
// Kelompokkan berdasarkan mig_nomor_lpj
|
||||
$groupedRows = $this->groupRowsByJaminan($rows);
|
||||
|
||||
print_r($groupedRows);
|
||||
|
||||
foreach ($groupedRows as $nomorLpj => $groupRows) {
|
||||
try {
|
||||
// Dapatkan info permohonan untuk update inspeksi
|
||||
$nomorRegis = $this->getNomorRegistrasiPermohonan($nomorLpj, $branchCache);
|
||||
if (!$nomorRegis) {
|
||||
Log::warning("Nomor registrasi tidak ditemukan untuk nomor LPJ: {$nomorLpj}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bangun JSON data pembanding
|
||||
$pembandingJson = $this->checkPembanding($groupRows);
|
||||
|
||||
print_r($pembandingJson);
|
||||
|
||||
// Update ke tabel inspeksi
|
||||
|
||||
// print_r($pembandingJson);
|
||||
Inspeksi::where('permohonan_id', $nomorRegis['id'])
|
||||
->where('dokument_id', $nomorRegis['dokument_id'])
|
||||
->update([
|
||||
'data_pembanding' => $pembandingJson,
|
||||
'updated_at' => now()
|
||||
]);
|
||||
|
||||
$this->command->info("Berhasil update data_pembanding untuk nomor LPJ: {$nomorLpj}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error pada nomor LPJ {$nomorLpj}: " . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
private function groupRowsByJaminan(array $rows): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$nomorJaminan = $row['mig_nomor_lpj'] ?? null;
|
||||
|
||||
if (!empty($nomorJaminan)) {
|
||||
$grouped[$nomorJaminan][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
private function checkPembanding(array $rows)
|
||||
{
|
||||
$pembandingList = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
// Pastikan kolom penting tersedia
|
||||
$urutan = (int)($row['mig_urutan'] ?? 999);
|
||||
$pembanding = trim($row['mig_pembanding'] ?? '');
|
||||
|
||||
// CUKUP VALIDASI PEMBANDING SAJA
|
||||
if (empty($pembanding)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pembandingList[] = [
|
||||
'urutan' => $urutan,
|
||||
'keterangan' => $pembanding,
|
||||
];
|
||||
}
|
||||
|
||||
// Urutkan berdasarkan urutan
|
||||
usort($pembandingList, function ($a, $b) {
|
||||
return $a['urutan'] <=> $b['urutan'];
|
||||
});
|
||||
|
||||
// Hapus indeks 'urutan'
|
||||
$finalPembanding = array_map(function ($item) {
|
||||
unset($item['urutan']);
|
||||
return $item;
|
||||
}, $pembandingList);
|
||||
|
||||
return json_encode([
|
||||
'data_pembanding' => $finalPembanding
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
private function getNomorRegistrasiPermohonan($nomor_jaminan_id, array &$cache)
|
||||
{
|
||||
if (isset($cache[$nomor_jaminan_id])) {
|
||||
return $cache[$nomor_jaminan_id];
|
||||
}
|
||||
|
||||
$permohonan = Permohonan::where('nomor_lpj', $nomor_jaminan_id)->first();
|
||||
|
||||
if (!$permohonan) {
|
||||
$cache[$nomor_jaminan_id] = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
$dokumenJaminan = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
|
||||
$result = [
|
||||
'id' => $permohonan->id,
|
||||
'dokument_id' => $dokumenJaminan ? $dokumenJaminan->id : null
|
||||
];
|
||||
|
||||
$cache[$nomor_jaminan_id] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
// Hapus file lama jika ada
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_mst_jaminan_nomor_jaminan', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError($nomorJaminan, string $message)
|
||||
{
|
||||
Log::error("Error migrasi permohonan [$nomorJaminan]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$nomorJaminan, $message]);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Lpj\Models\HubunganPemilikJaminan;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\PemilikJaminan;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Village;
|
||||
|
||||
class MigrationPemilikJaminanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$filePath = realpath(__DIR__ . '/csv/mig_dokument_dan_pemilik.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File CSV tidak ditemukan: ' . __DIR__ . '/csv/pemilik.csv');
|
||||
$this->command->error('File CSV tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 100; // Ukuran batch
|
||||
$branchCache = [];
|
||||
$debitureCache = [];
|
||||
$hubunganPemilikCache = [];
|
||||
$provinceCache = [];
|
||||
$cityCache = [];
|
||||
$districtCache = [];
|
||||
$subdistrictCache = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$this->processBatch($rows, $branchCache, $debitureCache, $hubunganPemilikCache, $provinceCache, $cityCache, $districtCache, $subdistrictCache);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
if (!empty($rows)) {
|
||||
$this->processBatch($rows, $branchCache, $debitureCache, $hubunganPemilikCache, $provinceCache, $cityCache, $districtCache, $subdistrictCache);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info('Data permohonan berhasil dimigrasikan.');
|
||||
}
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$debitureCache, array &$hubunganPemilikCache, array &$provinceCache, array &$cityCache, array &$districtCache, array &$subdistrictCache)
|
||||
{
|
||||
foreach ($rows as $index => $row) {
|
||||
$debitureId = $this->getDebiturId($row['mig_kd_debitur_seq'], $debitureCache);
|
||||
|
||||
if (!$debitureId) {
|
||||
Log::warning('Debitur tidak ditemukan untuk kode: ' . $row['mig_kd_debitur_seq']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$hubunganPemilik = $this->getHubunganPemilikId($row['mig_hubungan_pemilik_jaminan'], $hubunganPemilikCache);
|
||||
|
||||
|
||||
$proviceCode = $this->getProvinceCode($row['mig_province_name'], $provinceCache);
|
||||
$cityCode = $this->getCityCode($row['mig_city_name'], $cityCache);
|
||||
$districtCode = $this->getDistrictCode($row['mig_district_name'], $districtCache);
|
||||
|
||||
$subdistrictCode = $this->getSubdistrictCode($row['mig_village_name'], $subdistrictCache, $districtCache);
|
||||
|
||||
|
||||
PemilikJaminan::create([
|
||||
'debiture_id' => $debitureId,
|
||||
'hubungan_pemilik_jaminan_id' => $hubunganPemilik,
|
||||
'name' => $row['name'],
|
||||
'detail_sertifikat' => null,
|
||||
'npwp' => null,
|
||||
'nomor_id' => null,
|
||||
'email' => null,
|
||||
'phone' => null,
|
||||
'province_code' => $proviceCode,
|
||||
'city_code' => $cityCode,
|
||||
'district_code' => $districtCode,
|
||||
'village_code' => $subdistrictCode['code'],
|
||||
'postal_code' => $subdistrictCode['postal_code'],
|
||||
'address' => $row['address'],
|
||||
'created_at' => $this->parseTimestamp($row['created_at']),
|
||||
'updated_at' => $this->parseTimestamp($row['updated_at']),
|
||||
'mig_kd_debitur_seq' => $row['mig_kd_debitur_seq'],
|
||||
'processed_at' => now(),
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
$this->command->info('Proses data Pemilik Jaminan ' . $row['name'] . ' (' . ($index + 1) . '/' . count($rows) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
private function getDebiturId(string $code, array &$cache): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$debitur = Debiture::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($debitur) {
|
||||
$cache[$code] = $debitur->id;
|
||||
return $debitur->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getHubunganPemilikId(string $name, array &$cache): ?int
|
||||
{
|
||||
// Normalisasi nama
|
||||
$normalizedName = strtolower(trim($name));
|
||||
|
||||
// Cek cache untuk menghindari query berulang
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Query database dengan pengamanan tambahan
|
||||
$hubunganPemilik = HubunganPemilikJaminan::whereRaw('LOWER(name) = ?', [$normalizedName])
|
||||
->whereNull('deleted_at') // Tambahkan ini jika Anda menggunakan soft deletes
|
||||
->first();
|
||||
|
||||
// Jika data ditemukan, simpan dalam cache
|
||||
if ($hubunganPemilik) {
|
||||
$cache[$normalizedName] = $hubunganPemilik->id;
|
||||
return $hubunganPemilik->id;
|
||||
}
|
||||
|
||||
// Default jika data tidak ditemukan
|
||||
$cache[$normalizedName] = 1; // Cache nilai default untuk menghindari query berulang
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
private function getProvinceCode(string $name, array &$cache): ?string
|
||||
{
|
||||
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$province = Province::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($province) {
|
||||
$cache[$normalizedName] = $province->code;
|
||||
return $province->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getCityCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$city = City::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($city) {
|
||||
$cache[$normalizedName] = $city->code;
|
||||
return $city->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDistrictCode(string $name, array &$cache): ?string
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
$district = District::whereRaw('LOWER(name) = ?', [strtolower($name)])->first();
|
||||
|
||||
if ($district) {
|
||||
$cache[$normalizedName] = $district->code;
|
||||
return $district->code;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getSubdistrictCode(string $name, array &$cache, array &$districtCache): ?array
|
||||
{
|
||||
$normalizedName = strtolower($name);
|
||||
|
||||
// Pastikan cache menyimpan array, bukan hanya kode
|
||||
if (isset($cache[$normalizedName])) {
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Ambil subdistrict dari database
|
||||
$subdistrict = Village::whereRaw('LOWER(name) = ?', [$normalizedName])->first();
|
||||
|
||||
// Jika ditemukan, simpan ke dalam cache sebagai array lengkap
|
||||
if ($subdistrict) {
|
||||
$cache[$normalizedName] = [
|
||||
'code' => $subdistrict->code,
|
||||
'postal_code' => $subdistrict->postal_code
|
||||
];
|
||||
return $cache[$normalizedName];
|
||||
}
|
||||
|
||||
// Jika tidak ditemukan, kembalikan null
|
||||
return [
|
||||
'code' => null,
|
||||
'postal_code' => null
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function parseDate(?string $date): ?string
|
||||
{
|
||||
try {
|
||||
return $date ? \Carbon\Carbon::createFromFormat('Y-m-d', $date)->toDateString() : null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing tanggal: ' . $date);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
return $timestamp ? \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString() : null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,435 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
use Modules\Lpj\Models\Laporan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MigrationPenilaiSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
protected $errorLogFile = __DIR__ . '/csv/penilai-laporan/mig_penilai_error.csv';
|
||||
public function run()
|
||||
{
|
||||
$this->initializeErrorLog();
|
||||
// Path ke file csv
|
||||
$filePath = realpath(__DIR__ . '/csv/penilai-laporan/mig_penilai.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File csv tidak ditemukan: ' . __DIR__ . '/csv/penilai-laporan/mig_penilai.csv');
|
||||
$this->command->error('File csv tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 500;
|
||||
$userData = [];
|
||||
$branchCache = []; // <-- Gunakan sebagai cache
|
||||
$totalData = 0;
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Skip header
|
||||
|
||||
$batchCount = 0;
|
||||
$currentRow = 0;
|
||||
$errorCount = 0;
|
||||
$errorDebitureIds = [];
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
Log::warning('Baris CSV memiliki jumlah kolom yang tidak sesuai: ' . json_encode($data));
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
// info_harga_laporan_202505021522.csv
|
||||
// print_r($rows);
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $userData, $errorCount, $errorDebitureIds, $totalData, $batchCount, $currentRow);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$this->command->info("Data debiture berhasil dimigrasikan. Total data: {$totalData}, Total batch: {$batchCount}");
|
||||
}
|
||||
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$userData, int &$errorCount, array &$errorDebitureIds, int $totalData, int $batchCount, int $currentRow)
|
||||
{
|
||||
// Kelompokkan berdasarkan mig_nomor_lpj
|
||||
$groupedRows = $this->groupRowsByLpj($rows);
|
||||
|
||||
foreach ($groupedRows as $nomorLpj => $groupRows) {
|
||||
try {
|
||||
// Ambil informasi permohonan dan dokument_id
|
||||
$nomorRegis = $this->getNomorRegistrasiPermohonan($nomorLpj, $branchCache);
|
||||
if (!$nomorRegis) {
|
||||
Log::warning("Nomor registrasi tidak ditemukan untuk nomor LPJ: {$nomorLpj}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Dapatkan type_penilai (misal: standar, sederhana)
|
||||
$firstRow = reset($groupRows);
|
||||
$typePenilai = $this->checkTypePenilai($firstRow['mig_kode_jenis_laporan'] ?? '');
|
||||
|
||||
if (!$typePenilai) {
|
||||
Log::warning("Tidak ada jenis laporan valid untuk nomor LPJ: {$nomorLpj}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Bangun JSON type_penilai
|
||||
$penilaiJson = $this->cekJenisPenilai($groupRows);
|
||||
|
||||
// Simpan ke tabel Penilai
|
||||
|
||||
// print_r(json_decode($penilaiJson, true));
|
||||
|
||||
// Mapping field JSON berdasarkan tipe penilaian
|
||||
$fillableFieldMap = [
|
||||
'memo' => 'memo',
|
||||
'standar' => 'lpj',
|
||||
'sederhana' => 'lpj',
|
||||
'call_report' => 'call_report',
|
||||
'rap' => 'rap',
|
||||
'resume' => 'resume'
|
||||
];
|
||||
|
||||
$fieldToUpdate = $fillableFieldMap[$typePenilai] ?? null;
|
||||
|
||||
if (!$fieldToUpdate) {
|
||||
Log::warning("Field tidak dikenali untuk tipe: {$typePenilai}");
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
|
||||
// NO: 001/241917/LPJ/PJ-2251/VII/24
|
||||
// 001 => kode cabang
|
||||
// 241917 => nomor lpj
|
||||
// LPJ => jenis laporan
|
||||
// PJ-2251 => nomor registrasi ambil nilai akhirnnya 242251
|
||||
// VII => bulan
|
||||
// 24 => tahun
|
||||
|
||||
// Generate nomor_laporan
|
||||
$tanggal = $firstRow['mig_crated_at'];
|
||||
$nomorD = $nomorRegis['nomor_registrasi'];
|
||||
$nomorRegistrasi = "PJ-{$nomorD}";
|
||||
$nomorLaporan = $this->generateNomorLaporan($typePenilai, $nomorLpj, $nomorRegistrasi, $tanggal);
|
||||
|
||||
|
||||
// Simpan atau update ke tabel Penilai
|
||||
$penilaiLP = Penilai::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $nomorRegis['id'],
|
||||
'dokument_id' => $nomorRegis['dokument_id']
|
||||
],
|
||||
[
|
||||
'type' => $typePenilai,
|
||||
$fieldToUpdate => $penilaiJson,
|
||||
'type_penilai' => $typePenilai,
|
||||
'created_at' => $this->parseTimestamp($tanggal),
|
||||
'updated_at' => $this->parseTimestamp($tanggal),
|
||||
]
|
||||
);
|
||||
|
||||
// Simpan ke tabel Laporan
|
||||
Laporan::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $penilaiLP->permohonan_id,
|
||||
'dokumen_jaminan_id' => $penilaiLP->dokument_id
|
||||
],
|
||||
[
|
||||
'nomor_laporan' => $nomorLaporan,
|
||||
'created_at' => $this->parseTimestamp($tanggal),
|
||||
'updated_at' => $this->parseTimestamp($tanggal)
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->command->info("Berhasil simpan data penilai untuk nomor LPJ: {$nomorLpj}");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Error pada nomor LPJ {$nomorLpj}: " . $e->getMessage());
|
||||
$errorCount++;
|
||||
$errorDebitureIds[] = $nomorLpj;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function getNomorRegistrasiPermohonan($nomorLpj, array &$cache)
|
||||
{
|
||||
if (isset($cache[$nomorLpj])) {
|
||||
return $cache[$nomorLpj];
|
||||
}
|
||||
|
||||
$permohonan = Permohonan::where('nomor_lpj', $nomorLpj)->first();
|
||||
|
||||
if (!$permohonan) {
|
||||
$cache[$nomorLpj] = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
$dokumenJaminan = DokumenJaminan::where('permohonan_id', $permohonan->id)->first();
|
||||
|
||||
$result = [
|
||||
'id' => $permohonan->id,
|
||||
'dokument_id' => $dokumenJaminan ? $dokumenJaminan->id : null,
|
||||
'nomor_registrasi' => $permohonan->nomor_registrasi
|
||||
];
|
||||
|
||||
$cache[$nomorLpj] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
private function groupRowsByLpj(array $rows): array
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$nomorLpj = $row['mig_nomor_lpj'] ?? null;
|
||||
|
||||
if (!empty($nomorLpj)) {
|
||||
$grouped[$nomorLpj][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
private function checkTypePenilai($type)
|
||||
{
|
||||
$data = [
|
||||
'MAK' => 'memo',
|
||||
'STD' => 'standar',
|
||||
'SPL' => 'sederhana',
|
||||
'RHP' => 'call-report',
|
||||
'RAP' => 'rap',
|
||||
'PRG' => 'resume',
|
||||
];
|
||||
|
||||
return $data[$type];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function cekJenisPenilai(array $groupRows)
|
||||
{
|
||||
// Urutkan grup berdasarkan mig_urutan_seq
|
||||
usort($groupRows, function ($a, $b) {
|
||||
return ($a['mig_urutan_seq'] ?? 999) <=> ($b['mig_urutan_seq'] ?? 999);
|
||||
});
|
||||
|
||||
// Inisialisasi struktur JSON
|
||||
$penilaiJson = [
|
||||
'luas_tanah' => null,
|
||||
'nilai_tanah_1' => null,
|
||||
'nilai_tanah_2' => null,
|
||||
'sarana_pelengkap_penilai' => null,
|
||||
'nilai_sarana_pelengkap_1' => null,
|
||||
'nilai_sarana_pelengkap_2' => null,
|
||||
'total_nilai_pasar_wajar' => null,
|
||||
'likuidasi' => null,
|
||||
'likuidasi_nilai_1' => null,
|
||||
'likuidasi_nilai_2' => null,
|
||||
'asuransi_luas_bangunan' => null,
|
||||
'asuransi_nilai_1' => null,
|
||||
'asuransi_nilai_2' => "0",
|
||||
'npw_tambahan' => []
|
||||
];
|
||||
|
||||
// Ambil mainRow (urutan pertama)
|
||||
$mainRow = null;
|
||||
foreach ($groupRows as $row) {
|
||||
if (($row['mig_urutan_seq'] ?? '') == 1) {
|
||||
$mainRow = $row;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Jika tidak ada mainRow, ambil baris pertama sebagai fallback
|
||||
if (!$mainRow && !empty($groupRows[0])) {
|
||||
$mainRow = $groupRows[0];
|
||||
}
|
||||
|
||||
if ($mainRow) {
|
||||
$penilaiJson['total_nilai_pasar_wajar'] = $mainRow['mig_nilai_total_nilai_pasar'] ?? null;
|
||||
$penilaiJson['likuidasi'] = $mainRow['mig_nilai_likudasi'] ?? null;
|
||||
|
||||
// Hitung likuidasi nilai 2 jika ada total dan persen likuidasi
|
||||
$totalPasarWajar = (int)str_replace('.', '', $mainRow['mig_nilai_total_nilai_pasar'] ?? 0);
|
||||
$persenLikuidasi = (int)($mainRow['mig_nilai_likudasi'] ?? 0);
|
||||
$penilaiJson['likuidasi_nilai_1'] = $mainRow['mig_nilai_total_nilai_pasar'] ?? null;
|
||||
$penilaiJson['likuidasi_nilai_2'] = number_format(
|
||||
$totalPasarWajar * ($persenLikuidasi / 100),
|
||||
0,
|
||||
'',
|
||||
''
|
||||
);
|
||||
|
||||
// Isi data utama hanya untuk urutan 1
|
||||
$penilaiJson['luas_tanah'] = $mainRow['mig_nilai_satuan'] ?? null;
|
||||
$penilaiJson['nilai_tanah_1'] = $mainRow['mig_harga_satuan'] ?? null;
|
||||
$penilaiJson['nilai_tanah_2'] = number_format(
|
||||
(int)str_replace('.', '', $mainRow['mig_nilai_satuan'] ?? 0) *
|
||||
(int)str_replace('.', '', $mainRow['mig_harga_satuan'] ?? 0),
|
||||
0,
|
||||
'',
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
// Proses tambahan (urutan > 1)
|
||||
foreach ($groupRows as $row) {
|
||||
// Skip baris dengan urutan_seq = 1 karena sudah diproses
|
||||
if (($row['mig_urutan_seq'] ?? '') == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Hanya proses jika mig_urutan_seq ada
|
||||
$urutan = $row['mig_urutan_seq'] ?? '';
|
||||
if (empty($urutan)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tambahkan ke npw_tambahan
|
||||
$penilaiJson['npw_tambahan'][] = [
|
||||
'name' => $row['mig_keterangan'] ?? 'Luas Bangunan Tambahan',
|
||||
'luas' => $row['mig_nilai_satuan'] ?? null,
|
||||
'nilai_1' => $row['mig_harga_satuan'] ?? null,
|
||||
'nilai_2' => number_format(
|
||||
(int)str_replace('.', '', $row['mig_nilai_satuan'] ?? 0) *
|
||||
(int)str_replace('.', '', $row['mig_harga_satuan'] ?? 0),
|
||||
0,
|
||||
'',
|
||||
''
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
// Kosongkan npw_tambahan jika kosong
|
||||
if (empty($penilaiJson['npw_tambahan'])) {
|
||||
$penilaiJson['npw_tambahan'] = [];
|
||||
}
|
||||
|
||||
return json_encode($penilaiJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
private function convertToRoman($month)
|
||||
{
|
||||
$roman = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII'];
|
||||
return $month >= 1 && $month <= 12 ? $roman[$month - 1] : '';
|
||||
}
|
||||
|
||||
private function generateNomorLaporan($typePenilai, $nomorLpj, $nomorRegistrasi, $tanggal)
|
||||
{
|
||||
// Mapping type_penilai ke singkatan laporan
|
||||
$laporanMap = [
|
||||
'memo' => 'MEMO',
|
||||
'standar' => 'LPJ',
|
||||
'sederhana' => 'LPJ',
|
||||
'call_report' => 'CALL',
|
||||
'rap' => 'RAP',
|
||||
'resume' => 'RESUME'
|
||||
];
|
||||
|
||||
// Dapatkan tahun dan bulan dari tanggal
|
||||
$date = \Carbon\Carbon::parse($tanggal);
|
||||
$kodeCabang = '001'; // bisa diambil dari user atau parameter lain jika dinamis
|
||||
$tahun = substr($date->year, -2); // 2024 → 24
|
||||
$bulan = $this->convertToRoman($date->month); // 7 → VII
|
||||
|
||||
// Format akhir nomor registrasi (PJ-XXX)
|
||||
$nomorDebiturAkhir = substr($nomorRegistrasi, -4); // PJ-2251 → 2251
|
||||
|
||||
return sprintf(
|
||||
"%s/%s/%s/%s/%s/%s",
|
||||
$kodeCabang,
|
||||
$nomorLpj,
|
||||
$laporanMap[$typePenilai] ?? strtoupper($typePenilai),
|
||||
"PJ-" . $nomorDebiturAkhir,
|
||||
$bulan,
|
||||
$tahun
|
||||
);
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
if (file_exists($file)) {
|
||||
unlink($file); // Hapus file lama
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_kd_debitur_seq', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError(string $kode, string $message)
|
||||
{
|
||||
Log::error("Error migrasi dokumen jaminan [$kode]: $message");
|
||||
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$kode, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -1,376 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Basicdata\Models\Branch;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
class MigrationPermohonanSeeder extends Seeder
|
||||
{
|
||||
protected $errorLogFile = __DIR__ . '/csv/permohonan/mig_permohonan_extenal_error.csv';
|
||||
|
||||
public function run()
|
||||
{
|
||||
// Bersihkan file error sebelum mulai
|
||||
$this->initializeErrorLog();
|
||||
|
||||
$filePath = realpath(__DIR__ . '/csv/permohonan/mig_permohonan_external.csv');
|
||||
|
||||
if (!$filePath) {
|
||||
Log::error('File CSV tidak ditemukan: ' . __DIR__ . '/csv/permohonan/mig_permohonan_external.csv');
|
||||
$this->command->error('File CSV tidak ditemukan.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (($handle = fopen($filePath, 'r')) === false) {
|
||||
Log::error('Gagal membuka file CSV: ' . $filePath);
|
||||
$this->command->error('Gagal membuka file CSV.');
|
||||
return;
|
||||
}
|
||||
|
||||
$header = fgetcsv($handle, 0, '~');
|
||||
$rows = [];
|
||||
$batchSize = 1000;
|
||||
$branchCache = [];
|
||||
$debitureCache = [];
|
||||
$totalData = 0;
|
||||
$currentRow = 0;
|
||||
$batchCount = 0;
|
||||
|
||||
// Hitung total data
|
||||
while (fgetcsv($handle, 0, '~') !== false) {
|
||||
$totalData++;
|
||||
}
|
||||
|
||||
rewind($handle);
|
||||
fgetcsv($handle, 0, '~'); // Lewati header
|
||||
|
||||
while (($data = fgetcsv($handle, 0, '~')) !== false) {
|
||||
if (count($data) != count($header)) {
|
||||
$nomorJaminan = $data[array_search('mig_mst_jaminan_nomor_jaminan', $header)] ?? '-';
|
||||
$this->logError($nomorJaminan, 'Jumlah kolom tidak sesuai');
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = array_combine($header, $data);
|
||||
$currentRow++;
|
||||
// print_r($rows);
|
||||
if (count($rows) >= $batchSize) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $debitureCache, $totalData, $batchCount);
|
||||
$rows = [];
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($rows);
|
||||
|
||||
if (!empty($rows)) {
|
||||
$batchCount++;
|
||||
$this->command->info("Memproses batch ke-{$batchCount} ({$currentRow}/{$totalData})");
|
||||
$this->processBatch($rows, $branchCache, $debitureCache, $totalData, $batchCount);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info("Migrasi selesai. Total data diproses: $totalData.");
|
||||
}
|
||||
|
||||
private function processBatch(array $rows, array &$branchCache, array &$debitureCache, int $totalData, int $batchCount)
|
||||
{
|
||||
$userData = [];
|
||||
foreach ($rows as $index => $row) {
|
||||
try {
|
||||
$nomorJaminan = $row['mig_mst_jaminan_nomor_jaminan'] ?? '-';
|
||||
|
||||
// Cek apakah sudah diproses
|
||||
$existingRecord = Permohonan::where('nomor_registrasi', $row['mig_mst_jaminan_nomor_jaminan'])->first();
|
||||
if ($existingRecord && $existingRecord->processed_at) {
|
||||
$this->command->info("Data sudah diproses: $nomorJaminan");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil branch_id
|
||||
$branchId = $this->getBranchId($row['mig_mst_jaminan_kd_cabang'] ?? null, $branchCache);
|
||||
// if (!$branchId) {
|
||||
// $this->logError($branchId, 'Cabang tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Ambil Debitur ID
|
||||
$debitureId = $this->getDebiturId($row['mig_mst_jaminan_kd_debitur_seq'], $debitureCache);
|
||||
if (!$debitureId) {
|
||||
$this->logError($nomorJaminan, 'Debitur tidak ditemukan');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ambil User IDs
|
||||
$userId = $this->getUserId($row['mig_mst_jaminan_nama_ao'], $branchCache, true);
|
||||
|
||||
// jika external matikan
|
||||
// $approved1Id = $this->getUserId($row['mig_mst_lpj_user_approved_1'], $branchCache, false);
|
||||
// $approved2Id = $this->getUserId($row['mig_mst_lpj_user_approved_2'], $branchCache, false);
|
||||
|
||||
// // Ambil user IDs berdasarkan NIK
|
||||
$userIdUpdate = $this->getUserIdData($row['mig_mst_jaminan_user_create'] ?? null, $userData)['id'];
|
||||
$userIdOtorisasi = $this->getUserIdData($row['mig_mst_jaminan_user_oto'] ?? null, $userData)['id'];
|
||||
|
||||
// jika external matikan
|
||||
// if (!$userIdUpdate || !$userIdOtorisasi) {
|
||||
// $this->logError($userIdUpdate, 'Salah satu user tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Mapping field user
|
||||
$mapUser = [
|
||||
'created_by' => $userIdUpdate,
|
||||
'updated_by' => $userIdUpdate,
|
||||
'authorized_by' => $userIdOtorisasi,
|
||||
];
|
||||
|
||||
// jika external matikan
|
||||
// if (!$userId || !$approved1Id || !$approved2Id) {
|
||||
// $this->logError($userId, 'Salah satu user tidak ditemukan');
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// Mapping data
|
||||
$jenisFasilitas = $this->checkJenisFasilitas($row['mig_mst_jaminan_kd_jenis_fas_seq']);
|
||||
$tujuanPenilaian = $this->checkTujuanPenilaian($row['mig_mst_jaminan_kd_tujuan_seq']);
|
||||
$regionId = $this->checkRegion($row['mig_mst_kode_kelompok_region']);
|
||||
|
||||
|
||||
$nomor_lpj = isset($row['mig_mst_lpj_nomor_lpj']) ? $row['mig_mst_lpj_nomor_lpj'] : '';
|
||||
$nomor_lpj = is_numeric($nomor_lpj) ? (int)$nomor_lpj : 0;
|
||||
|
||||
$jenisPenilaian = $row['mig_internal_or_external'] == 1 ? 2 : 1;
|
||||
|
||||
// Simpan data
|
||||
Permohonan::create([
|
||||
'nomor_registrasi' => $nomorJaminan,
|
||||
'tanggal_permohonan' => $this->parseDate($row['tanggal_permohonan']),
|
||||
'user_id' => $userId['id'],
|
||||
'branch_id' => $branchId,
|
||||
'tujuan_penilaian_id' => $tujuanPenilaian,
|
||||
'debiture_id' => $debitureId,
|
||||
'jenis_fasilitas_kredit_id' => $jenisFasilitas,
|
||||
'nilai_plafond_id' => 2,
|
||||
'status' => 'done',
|
||||
// jika external matikan
|
||||
// 'approval_eo' => $approved2Id['id'] ?? 0,
|
||||
// 'approval_eo_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_2']),
|
||||
// 'approval_dd' => 0,
|
||||
// 'approval_dd_at' => null,
|
||||
// 'approval_so' => $approved1Id['id'] ?? 0,
|
||||
// 'approval_so_at' => $this->parseTimestamp($row['mig_mst_lpj_tgl_approved_1']),
|
||||
// end external matikan
|
||||
'keterangan' => $row['mig_mst_jaminan_catatan'] ?? null,
|
||||
'status_bayar' => 'sudah_bayar',
|
||||
'created_at' => $this->parseTimestamp($row['mig_mst_jaminan_tgl_create']),
|
||||
'updated_at' => $this->parseTimestamp($row['mig_mst_jaminan_tgl_update']),
|
||||
'mig_kd_debitur_seq' => $row['mig_mst_jaminan_kd_debitur_seq'],
|
||||
'nomor_lpj' => $nomor_lpj,
|
||||
'region_id' => $regionId,
|
||||
'jenis_penilaian_id' => $jenisPenilaian,
|
||||
'authorized_by' => $mapUser['authorized_by'],
|
||||
'created_by' => $mapUser['created_by'],
|
||||
'updated_by' => $mapUser['updated_by'],
|
||||
'mig_nama_ao' => $row['mig_mst_jaminan_nama_ao'],
|
||||
'is_mig' => 1
|
||||
]);
|
||||
|
||||
$this->command->info("Proses data permohonan $nomorJaminan (" . ($index + 1) . '/' . count($rows) . " pada batch ke-$batchCount)");
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$nomorJaminan = $row['mig_mst_jaminan_nomor_jaminan'] ?? '-';
|
||||
$this->logError($nomorJaminan, "Error eksepsi: " . $e->getMessage());
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getUserIdData(?string $code, array &$cache): array
|
||||
{
|
||||
if (!$code) {
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$user = User::where('nik', $code)->first();
|
||||
|
||||
if ($user) {
|
||||
$cache[$code] = ['id' => $user->id, 'branch_id' => $user->branch_id];
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
private function getUserId(string $value, array &$cache, bool $includeBranch = false): ?array
|
||||
{
|
||||
if (isset($cache[$value])) {
|
||||
return $cache[$value];
|
||||
}
|
||||
|
||||
$user = null;
|
||||
|
||||
if ($includeBranch) {
|
||||
$user = User::whereRaw('LOWER(name) = ?', [strtolower($value)])->first();
|
||||
} else {
|
||||
$user = User::where('nik', $value)->first();
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$result = ['id' => $user->id];
|
||||
if ($includeBranch) {
|
||||
$result['branch_id'] = $user->branch_id;
|
||||
}
|
||||
$cache[$value] = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
return ['id' => null, 'branch_id' => null];
|
||||
}
|
||||
|
||||
private function getDebiturId(string $code, array &$cache): ?int
|
||||
{
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$debitur = Debiture::where('mig_kd_debitur_seq', $code)->first();
|
||||
|
||||
if ($debitur) {
|
||||
$cache[$code] = $debitur->id;
|
||||
return $debitur->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private function getBranchId(?string $code, array &$cache): ?int
|
||||
{
|
||||
if (!$code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($cache[$code])) {
|
||||
return $cache[$code];
|
||||
}
|
||||
|
||||
$branch = Branch::where('code', $code)->first();
|
||||
|
||||
if ($branch) {
|
||||
$cache[$code] = $branch->id;
|
||||
return $branch->id;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private function checkJenisFasilitas($code): int
|
||||
{
|
||||
$mapping = [
|
||||
161337594516 => 1,
|
||||
161337598118 => 14,
|
||||
155739382483 => 7,
|
||||
2 => 9,
|
||||
153568936592 => 10,
|
||||
155737674431 => 11,
|
||||
161337561199 => 12,
|
||||
1 => 13,
|
||||
];
|
||||
|
||||
return $mapping[$code] ?? 0;
|
||||
}
|
||||
|
||||
private function checkTujuanPenilaian($code): int
|
||||
{
|
||||
$mapping = [
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
3 => 9,
|
||||
4 => 10,
|
||||
5 => 8,
|
||||
6 => 3,
|
||||
];
|
||||
|
||||
return $mapping[$code] ?? 1;
|
||||
}
|
||||
|
||||
private function checkRegion($code): int
|
||||
{
|
||||
$mapping = [
|
||||
'01' => 1,
|
||||
'02' => 2,
|
||||
'04' => 3,
|
||||
'07' => 4,
|
||||
'06' => 5,
|
||||
];
|
||||
|
||||
return $mapping[$code] ?? 1;
|
||||
}
|
||||
|
||||
private function parseDate(?string $date): ?string
|
||||
{
|
||||
try {
|
||||
return $date ? \Carbon\Carbon::createFromFormat('Y-m-d', $date)->toDateString() : null;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function parseTimestamp(?string $timestamp): ?string
|
||||
{
|
||||
try {
|
||||
if ($timestamp) {
|
||||
// Cek jika format hanya tanggal (Y-m-d)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $timestamp)) {
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d', $timestamp)
|
||||
->startOfDay()
|
||||
->toDateTimeString();
|
||||
}
|
||||
// Format lengkap (Y-m-d H:i:s)
|
||||
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->toDateTimeString();
|
||||
}
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Gagal memparsing timestamp: ' . $timestamp . '. Pesan: ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function initializeErrorLog()
|
||||
{
|
||||
$file = $this->errorLogFile;
|
||||
|
||||
// Hapus file lama jika ada
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// Buat file baru dengan header
|
||||
$handle = fopen($file, 'w');
|
||||
fputcsv($handle, ['mig_mst_jaminan_nomor_jaminan', 'Error']);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
private function logError($nomorJaminan, string $message)
|
||||
{
|
||||
Log::error("Error migrasi permohonan [$nomorJaminan]: $message");
|
||||
|
||||
// Tulis ke file error
|
||||
$handle = fopen($this->errorLogFile, 'a');
|
||||
fputcsv($handle, [$nomorJaminan, $message]);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PosisiKavlingSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// $this->call([]);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace Modules\Lpj\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Lpj\Models\Teams;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TeamsSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
@@ -12,6 +12,14 @@ class TeamsSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::unprepared(file_get_contents(__DIR__ . '/sql/teams.sql'));
|
||||
Teams::insert([
|
||||
[
|
||||
'regions_id' => 1,
|
||||
'code' => 'T01',
|
||||
'name' => 'Team 1',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,36 +40,7 @@ class TujuanPenilaianKJPPSeeder extends Seeder
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'TPK05',
|
||||
'name' => 'Penilaian Ulang Jaminan / Review Tahunan',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'TPK06',
|
||||
'name' => 'Lelang',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'TPK07',
|
||||
'name' => 'Permohonan Baru',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'TPK08',
|
||||
'name' => 'Penambahan Fasilitas / Jaminan',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,38 +60,7 @@ class TujuanPenilaianSeeder extends Seeder
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'deleted_at' => null,
|
||||
],
|
||||
[
|
||||
'code' => 'TP0007',
|
||||
'name' => 'Jual Beli',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'deleted_at' => null,
|
||||
],
|
||||
[
|
||||
'code' => 'TP0008',
|
||||
'name' => 'KPR eks BPPN',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'deleted_at' => null,
|
||||
],
|
||||
[
|
||||
'code' => 'TP0009',
|
||||
'name' => 'Penambahan Fasilitas / Jaminan',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
],
|
||||
[
|
||||
'code' => 'TP00010',
|
||||
'name' => 'Penukaran Jaminan',
|
||||
'status' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now()
|
||||
]
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
INSERT INTO `fasilitas_objek` (`id`, `code`, `name`, `status`, `authorized_status`, `created_at`, `updated_at`, `authorized_at`, `authorized_by`, `deleted_at`, `created_by`, `updated_by`, `deleted_by`) VALUES
|
||||
(1, 'FU001', 'Tempat Ibadah', 1, NULL, '2024-11-28 18:57:35', '2024-11-28 18:57:35', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(2, 'FU002', 'Rumah Sakit', 1, NULL, '2024-11-28 18:57:50', '2024-11-28 18:57:50', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(3, 'FU003', 'Sekolah', 1, NULL, '2024-11-28 18:58:05', '2024-11-28 18:58:05', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(4, 'FU004', 'Kantor Pemerintahan', 1, NULL, '2024-11-28 18:58:27', '2024-11-28 18:58:27', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(5, 'FU005', 'Stasiun Kereta', 1, NULL, '2024-11-28 18:58:49', '2024-11-28 18:58:49', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(6, 'FU006', 'Terminal Bus', 1, NULL, '2024-11-28 18:59:09', '2024-11-28 18:59:09', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(7, 'FU007', 'Bandara', 1, NULL, '2024-11-28 18:59:26', '2024-11-28 18:59:26', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(8, 'FU009', 'Pos Polisi', 1, NULL, '2024-11-28 18:59:50', '2024-11-28 18:59:50', NULL, NULL, NULL, NULL, NULL, NULL),
|
||||
(9, 'FU010', 'Lainnya', 1, NULL, '2024-11-28 19:00:07', '2024-11-28 19:00:07', NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user