Commit 43c47728 by Triyah Fatmawati

Add regenerate VA

parent fb680512
......@@ -385,6 +385,61 @@ public function store(Request $request) {
}
}
public function regenerateVa($id){
$registrasi = Registrasi::query()->find($id);
if(!is_null($registrasi->tanggal_bayar)){
return redirect()->route('admin.index_peserta')
->with('error', 'Tagihan telah dibayar!');
}
else{
DB::beginTransaction();
try{
$namanya = str_replace(["'", ".", ",", "-"], '', $registrasi->nama);
$nama = Str::substr($namanya, 0, 30);
$multipartData = [
'noid' => $registrasi->kode_registrasi,
'nama' => $nama,
'tagihan' => $registrasi->tagihan
];
$generatedVa = $this->generateVa($multipartData);
$arrResponse = json_decode($generatedVa, true);
$registrasi['status_va'] = $arrResponse['BTNresponse'];
$registrasi['nomor_va'] = $arrResponse['BTNVirtualAccount'];
$registrasi['updated_at'] = Carbon::now()->toDateTimeString();
$registrasi->save();
if($arrResponse['BTNresponse'] != 'Request has been processed successfully'){
DB::rollBack();
Log::error('---');
Log::error($multipartData);
Log::error($arrResponse['BTNresponse']);
Log::error('---');
return redirect()->route('admin.index_peserta')
->with('error', 'VA gagal di-regenerate');
}
DB::commit();
return redirect()->route('admin.index_peserta')
->with('success', 'VA berhasil di-regenerate');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return redirect()->route('admin.index_peserta')
->with('error', 'VA gagal di-regenerate');
}
}
}
private function generateVa($multipartData)
{
$client = new Client();
......
......@@ -58,7 +58,7 @@
@endforeach
</td>
<td>
{{-- <button type="button" class="btn btn-info" data-toggle="modal" data-target="#update-modal{{$p->id}}"><i class="fa fa-check" aria-hidden="true"></i></button> --}}
<a href="{{route('regenerateVa', ['id' => $p->id])}}" type="button" class="btn btn-warning"><i class="fa fa-refresh" aria-hidden="true"></i> Re-Generate VA</a>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#detail-modal{{$p->id}}"><i class="fa fa-search" aria-hidden="true"></i></button>
{{-- <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete-modal{{$p->id}}"><i class="fa fa-trash" aria-hidden="true"></i></button> --}}
......@@ -126,12 +126,12 @@
<div class="col-6 mt-2 form-group">
<label for="nomor_registrasi">Nomor Registrasi</label>
<input type="text" class="form-control" id="nomor_registrasi" name="nomor_registrasi" value="{{ $p->kode_registrasi }}">
</div>
<div class="col-6 mt-2 form-group">
<label for="nik">NIK</label>
<input type="number" class="form-control" id="nik" name="nik" value="{{ $p->nik }}">
</div>
</div>
<div class="row">
......
......@@ -18,6 +18,7 @@
Route::get('/individu', [RegistrasiController::class,'create'])->name('user.create');
Route::get('/kelompok', [RegistrasiController::class,'group_create'])->name('group.create');
Route::get('/regenerateVa/{id}', [RegistrasiController::class,'regenerateVa'])->name('regenerateVa');
// Route::get('/', function(Request $request){
// return view('penutupan');
// });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment