Commit 7934d8fe by Triyah Fatmawati

Add preview sebelum daftar

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