Commit 7934d8fe by Triyah Fatmawati

Add preview sebelum daftar

parent bd469041
......@@ -5,8 +5,24 @@
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use RealRashid\SweetAlert\Facades\Alert;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
public function __construct()
{
$this->middleware(function($request,$next){
if (session('success')) {
Alert::success(session('success'));
}
if (session('error')) {
Alert::error(session('error'));
}
return $next($request);
});
}
}
......@@ -14,29 +14,30 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use RealRashid\SweetAlert\Facades\Alert;
class RegistrasiController extends Controller
{
public function create(){
$kegiatan = Kegiatan::get();
$kegiatan = Kegiatan::orderBy('id')->get();
$konferensi = Konferensi::get();
$date = Date('Y-m-d');
$lastKode = Registrasi::query()->whereDate('created_at', $date)->max('kode_registrasi');
$nourut = sprintf("%05s", ((int) substr($lastKode, -5))+1);
$tgldaftar = Carbon::now()->format('d-m-Y');
$komponen = explode('-', $tgldaftar);
$kode_registrasi = $komponen[0].$komponen[1].$nourut;
// $lastKode = Registrasi::query()->whereDate('created_at', $date)->max('kode_registrasi');
// $nourut = sprintf("%05s", ((int) substr($lastKode, -5))+1);
// $tgldaftar = Carbon::now()->format('d-m-Y');
// $komponen = explode('-', $tgldaftar);
// $kode_registrasi = $komponen[0].$komponen[1].$nourut;
$data = [
'kegiatan' => $kegiatan,
'konferensi' => $konferensi,
// 'kode_registrasi' => $kode_registrasi
];
return view('form_registrasi', $data);
}
public function store(Request $request) {
public function preview(Request $request){
$rules = [
'nama' => 'required|string',
'email' => 'required|email:rfc,dns',
......@@ -73,11 +74,8 @@ public function store(Request $request) {
];
$tglRegistrasi = Carbon::now()->format('Y-m-d h:i:s');
// $kegiatan = Kegiatan::find($request->kegiatan);
// $konferensi = Konferensi::find($request->konferensi);
$konaspi = Kegiatan::query()->where('id', '498633a9-082c-4a4a-9dbd-e20b678ec15e')->first();
$registrasi = Registrasi::query()->create($registrasi);
$id_registrasi = $registrasi->id;
//inisial harga
$totalHarga = (int) $konaspi->harga;
......@@ -93,7 +91,6 @@ public function store(Request $request) {
}
$kegiatanpeserta[] = [
'id_registrasi' => $id_registrasi,
'id_kegiatan' => $kegiatan[$i]['id'],
'id_konferensi' => $daftarKonferensi[$i],
'nama_kegiatan' => $kegiatan[$i]['nama'],
......@@ -111,30 +108,68 @@ public function store(Request $request) {
$totalHarga += (int) $konferensi->harga;
$i++;
}
foreach($kegiatanpeserta as $keg){
KegiatanPeserta::query()->create($keg);
}
}
else{
$hargaKonferensi = null;
$kegiatanpeserta = [
'id_registrasi' => $id_registrasi,
$kegiatanpeserta[] = [
'id_kegiatan' => $request->kegiatan0[0],
'id_konferensi' => null,
];
KegiatanPeserta::query()->create($kegiatanpeserta);
}
$data = [
'registrasi' => $registrasi,
'kegiatanpeserta' => $kegiatanpeserta,
'tglRegistrasi' => $tglRegistrasi,
'konaspi' => $konaspi,
'hargaKonferensi' => $hargaKonferensi,
'totalHarga' => $totalHarga
];
return view('invoice', $data)->with('success', 'Data saved successfully');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return redirect()->back()
->with('error', 'Data failed to save');
}
}
public function store(Request $request) {
DB::beginTransaction();
try{
$registrasi = json_decode($request->registrasi, true);
$kegiatanpeserta = json_decode($request->kegiatanpeserta, true);
$konaspi = json_decode($request->konaspi, true);
$hargaKonferensi = json_decode($request->hargaKonferensi, true);
$tglRegistrasi = $request->tglRegistrasi;
$totalHarga = $request->totalHarga;
$registrasi = Registrasi::query()->create($registrasi);
$id_registrasi = $registrasi->id;
$jumlahKeg = count($kegiatanpeserta);
foreach($kegiatanpeserta as $keg){
$kegpeserta = [
'id_registrasi' => $id_registrasi,
'id_kegiatan' => $keg['id_kegiatan'],
'id_konferensi' => $keg['id_konferensi'],
];
KegiatanPeserta::query()->create($kegpeserta);
}
$multipartData = [
'noid' => $kode_registrasi,
'nama' => $request->nama,
'noid' => $registrasi['kode_registrasi'],
'nama' => $registrasi['nama'],
'tagihan' => $totalHarga
];
$generatedVa = $this->generateVa($multipartData);
$arrResponse = json_decode($generatedVa, true);
$registrasi->status_va = $arrResponse['BTNresponse'];
$registrasi->tagihan = $totalHarga;
......@@ -153,24 +188,14 @@ public function store(Request $request) {
DB::commit();
// return redirect()->back()
// ->with('success', 'Data saved successfully');
$data = [
'registrasi' => $registrasi,
'tglRegistrasi' => $tglRegistrasi,
'konaspi' => $konaspi,
'hargaKonferensi' => $hargaKonferensi
];
return view('invoice', $data)->with('success', 'Data saved successfully');
return redirect()->route('user.create')->with('success', 'Data saved successfully');
}
catch(Exception $e){
Log::error($e);
DB::rollBack();
return redirect()->back()
return redirect()->route('user.create')
->with('error', 'Data failed to save');
}
}
......
......@@ -8812,5 +8812,5 @@
"php": "^8.1"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}
......@@ -11,14 +11,14 @@
@if ($i != 0)
@if ($keg->id != "498633a9-082c-4a4a-9dbd-e20b678ec15e")
<div class="form-check">
<input class="form-check-input" type="radio" id="nama-kegiatan-{{ $i }}-{{ $j }}" name="kegiatan{{ $i }}[]" value="{{ $keg->id }}" onChange="cekKegiatan('nama-kegiatan-{{ $i }}-{{ $j }}')">
<label class="form-check-label" for="{{ $keg->nama }}">{{ $keg->nama }}</label>
<input class="form-check-input" type="radio" id="nama-kegiatan-{{ $i }}-{{ $j }}" name="kegiatan{{ $i }}[]" value="{{ $keg->id }}" onChange="cekKegiatan('nama-kegiatan-{{ $i }}-{{ $j }}')" required>
<label class="form-check-label" for="nama-kegiatan-{{ $i }}-{{ $j }}">{{ $keg->nama }}</label>
</div>
@endif
@else
<div class="form-check">
<input class="form-check-input" type="radio" id="nama-kegiatan-{{ $i }}-{{ $j }}" name="kegiatan{{ $i }}[]" value="{{ $keg->id }}" onChange="cekKegiatan('nama-kegiatan-{{ $i }}-{{ $j }}')">
<label class="form-check-label" for="{{ $keg->nama }}">{{ $keg->nama }}</label>
<input class="form-check-input" type="radio" id="nama-kegiatan-{{ $i }}-{{ $j }}" name="kegiatan{{ $i }}[]" value="{{ $keg->id }}" onChange="cekKegiatan('nama-kegiatan-{{ $i }}-{{ $j }}')" required>
<label class="form-check-label" for="nama-kegiatan-{{ $i }}-{{ $j }}">{{ $keg->nama }}</label>
</div>
@endif
@endforeach
......
......@@ -8,7 +8,7 @@
</div>
</div>
<form class="needs-validation" novalidate="" method="POST" action="{{ route('user.store')}}" enctype="multipart/form-data">
<form class="needs-validation" novalidate="" method="POST" action="{{ route('user.preview')}}" enctype="multipart/form-data">
<div class="section-body">
@csrf
<div class="row">
......@@ -120,14 +120,14 @@
</div>
<hr>
<div class="card">
<div class="card-body">
{{-- <div class="form-group" @if ($errors->has('kode_registrasi')) has-error @endif>
{{-- <div class="card-body">
<div class="form-group" @if ($errors->has('kode_registrasi')) has-error @endif>
<label>Kode Registrasi</label>
<input type="text" id="kode_registrasi" name="kode_registrasi" class="form-control number" required="true" placeholder="" value="{{ $kode_registrasi }}">
@if ($errors->has('kode_registrasi'))
<label id="login-error" class="error" for="kode_registrasi" style="color: red">{{$errors->first('kode_registrasi')}}</label>
@endif
</div> --}}
</div>
<div class="form-group" @if ($errors->has('biaya')) has-error @endif>
<label>Biaya Pendaftaran</label>
<input type="text" id="biaya" name="biaya" class="form-control number" required="true" placeholder="" value="{{ old('biaya')}}" disabled>
......@@ -135,7 +135,7 @@
<label id="login-error" class="error" for="biaya" style="color: red">{{$errors->first('biaya')}}</label>
@endif
</div>
</div>
</div> --}}
</div>
</div>
</div>
......@@ -197,8 +197,6 @@ function hapusKegiatan(id){
$('#'+id).remove();
}
function cekHarga(){
console.log('masuk');
}
</script>
@endpush
......@@ -17,7 +17,7 @@
Route::get('/', [RegistrasiController::class,'create'])->name('user.create');
Route::post('/store', [RegistrasiController::class,'store'])->name('user.store');
Route::get('/cekHarga', [RegistrasiController::class,'cekHarga'])->name('user.cekharga');
Route::post('/preview', [RegistrasiController::class,'preview'])->name('user.preview');
Route::get('/home', [AdminController::class,'index'])->name('admin.home');
......
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