Skip to content

Commit 6742207

Browse files
committed
Refactor WA group handling and update database schema for reminders
1 parent c410e69 commit 6742207

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

app/Helpers/Helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,8 @@ public static function sendReminder($reminder, $method = 'auto')
21612161
'{kegiatan}' => $kegiatan->kegiatan,
21622162
'{pj}' => $kegiatan->daftar_kegiatanable_type == \App\Models\UnitKerja::class ? UnitKerja::find($kegiatan->daftar_kegiatanable_id)->unit : User::find($kegiatan->daftar_kegiatanable_id)->name,
21632163
]);
2164-
$response = Fonnte::make()->sendWhatsAppMessage($kegiatan->wa_group_id, $pesan);
2164+
$recipients = implode(',',collect($kegiatan->wa_group_id)->pluck('id')->toArray());
2165+
$response = Fonnte::make()->sendWhatsAppMessage($recipients, $pesan);
21652166
$reminder->status = $response['data']['process'] ?? 'Gagal';
21662167
$reminder->message_id = $response['data']['id'][0];
21672168
$reminder->save();

app/Models/DaftarKegiatan.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected function casts(): array
2222
'awal' => 'datetime',
2323
'akhir' => 'datetime',
2424
'waktu_reminder' => 'array',
25+
'wa_group_id' => 'array',
2526
];
2627
}
2728

app/Nova/DaftarKegiatan.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,22 @@ public function fields(NovaRequest $request)
123123
]),
124124
Text::make('Status')->exceptOnForms(),
125125
Panel::make('Reminder', [
126-
Select::make('WA Group', 'wa_group_id')
127-
->options(Helper::setOptionsWaGroup())
126+
Repeatable::make('WA Group', 'wa_group_id', [
127+
Select::make('WA Group', 'id')
128+
->options(Helper::setOptionsWaGroup())
129+
->searchable()
130+
->rules('required')
131+
->displayUsingLabels()
132+
->help('Jika Pilihan Group belum tersedia, tambahkan nomor ini ke dalam Group WA Anda: <b>'.config('fonnte.number').'</b> Kemudian hubungi Admin'),
133+
])
128134
->hide()
129-
->searchable()
130-
->displayUsingLabels()
131-
->dependsOn(['jenis'], function (Select $field, NovaRequest $request, FormData $formData) {
135+
->dependsOn(['jenis'], function (Repeatable $field, NovaRequest $request, FormData $formData) {
132136
if ($formData->jenis === 'Deadline') {
133137
$field
134-
->rules('required')
135-
->show();
138+
->show()
139+
->rules('required');
136140
}
137-
})
138-
->hideFromIndex()
139-
->help('Jika Pilihan Group belum tersedia, tambahkan nomor ini ke dalam Group WA Anda: <b>'.config('fonnte.number').'</b> Kemudian hubungi Admin'),
141+
}),
140142
Textarea::make('Template Pesan', 'pesan')
141143
->hide()
142144
->help('Jangan hapus bagian {judul}.<br/> Gunakan {kegiatan} untuk mengganti dengan nama kegiatan,<br/> {tanggal} untuk mengganti tanggal deadline,<br/> {pj} untuk mengganti dengan penanggung jawab')

database/migrations/2024_12_27_145216_create_daftar_kegiatans_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function up(): void
1717
$table->string('kegiatan')->nullable();
1818
$table->dateTime('awal')->nullable();
1919
$table->dateTime('akhir')->nullable();
20-
$table->string('wa_group_id', 80)->nullable();
20+
$table->text('wa_group_id')->nullable();
2121
$table->text('pesan')->nullable();
2222
$table->text('waktu_reminder')->nullable();
2323
$table->string('status', 20)->nullable();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('daftar_kontrak_mitras', function (Blueprint $table) {
15+
$table->after('id', function (Blueprint $table) {
16+
$table->date('tanggal_spk')->nullable();
17+
$table->date('tanggal_bast')->nullable();
18+
});
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*/
25+
public function down(): void
26+
{
27+
Schema::table('daftar_kontrak_mitras', function (Blueprint $table) {
28+
$table->dropColumn('tanggal_spk');
29+
$table->dropColumn('tanggal_bast');
30+
});
31+
}
32+
};

0 commit comments

Comments
 (0)