From 222ada0f0cf72cd8e558292d767ce0a2e4ec7aaa Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 27 Feb 2025 13:18:15 +0700 Subject: [PATCH] fix(tender): perbaiki pengolahan email kantor - Mengubah cara pengolahan email dari string menjadi koleksi untuk menghindari duplikasi. - Memastikan bahwa detail email yang diambil dari JSON diproses dengan benar. - Menambahkan validasi untuk memastikan bahwa detail email adalah array sebelum diakses. --- app/Http/Controllers/TenderController.php | 51 +++++++++++++---------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/TenderController.php b/app/Http/Controllers/TenderController.php index 09bad66..8b0571f 100644 --- a/app/Http/Controllers/TenderController.php +++ b/app/Http/Controllers/TenderController.php @@ -700,15 +700,17 @@ class TenderController extends Controller $kjpps = KJPP::whereIn('id', $detail_penawaran) ->get() ->map(function ($item) { - $emails = [$item->email_kantor]; + $emails = collect(explode(',', $item->email_kantor))->filter()->unique(); // Parse JSON string jika ada dan tidak kosong if (!empty($item->detail_email_kantor) && $item->detail_email_kantor !== '[]') { $detail_emails = json_decode($item->detail_email_kantor, true); if (is_array($detail_emails)) { foreach ($detail_emails as $detail) { - if (isset($detail['email_kantor'])) { - $emails[] = $detail['email_kantor']; + if (is_array($detail) && isset($detail['email_kantor'])) { + $emails->push($detail['email_kantor']); + } elseif (is_string($detail)) { + $emails->push($detail); } } } @@ -716,10 +718,11 @@ class TenderController extends Controller return [ 'kjpp' => $item, - 'emails' => array_filter($emails) + 'emails' => array_filter($emails->unique()->values()->all()) ]; }); + foreach ($permohonan->documents as $document) { $village_permohonan = $document->village_code; $district_permohonan = $document->district_code; @@ -894,26 +897,30 @@ class TenderController extends Controller $detail_penawaran = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $id)->pluck('kjpp_rekanan_id')->toArray(); $kjpps = KJPP::whereIn('id', $detail_penawaran) - ->get() - ->map(function ($item) { - $emails = [$item->email_kantor]; + ->get() + ->map(function ($item) { + $emails = collect(explode(',', $item->email_kantor))->filter()->unique(); - // Parse JSON string jika ada dan tidak kosong - if (!empty($item->detail_email_kantor) && $item->detail_email_kantor !== '[]') { - $detail_emails = json_decode($item->detail_email_kantor, true); - if (is_array($detail_emails)) { - foreach ($detail_emails as $detail) { - if (isset($detail['email_kantor'])) { - $emails[] = $detail['email_kantor']; - } - } - } - } + // Parse JSON string jika ada dan tidak kosong + if (!empty($item->detail_email_kantor) && $item->detail_email_kantor !== '[]') { + $detail_emails = json_decode($item->detail_email_kantor, true); + if (is_array($detail_emails)) { + foreach ($detail_emails as $detail) { + if (is_array($detail) && isset($detail['email_kantor'])) { + $emails->add($detail['email_kantor']); + } elseif (is_string($detail)) { + $emails->add($detail); + } + } + } + } - return array_filter($emails); - }) - ->flatten() - ->toArray(); + return array_filter(array_values(iterator_to_array($emails))); + }) + ->flatten() + ->unique() + ->values() + ->toArray(); $dp1 = PenawaranDetailTender::with('kjpp')->where('kjpp_rekanan_id', '=', $id)->first();