Commit 1998f752 by Triyah Fatmawati

Perbaikan insert data

parent b77dc531
...@@ -18,23 +18,19 @@ ...@@ -18,23 +18,19 @@
class RegistrasiController extends Controller class RegistrasiController extends Controller
{ {
public function create(){ public function create(){
// $jumlahPendaftar = Registrasi::count();
// $nourut = sprintf("%05s", $jumlahPendaftar+1);
// $koderegistrasi = 'REG-'.$komponen[0].$komponen[1].$komponen[2].$nourut;
$kegiatan = Kegiatan::get(); $kegiatan = Kegiatan::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", 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);
$koderegistrasi = '-'; $kode_registrasi = $komponen[0].$komponen[1].$nourut;
$data = [ $data = [
'kegiatan' => $kegiatan, 'kegiatan' => $kegiatan,
'konferensi' => $konferensi, 'konferensi' => $konferensi,
'kode_registrasi' => $koderegistrasi // 'kode_registrasi' => $kode_registrasi
]; ];
return view('form_registrasi', $data); return view('form_registrasi', $data);
...@@ -50,7 +46,6 @@ public function store(Request $request) { ...@@ -50,7 +46,6 @@ public function store(Request $request) {
'alamat' => 'required|string', 'alamat' => 'required|string',
'kodepos' => 'required|string', 'kodepos' => 'required|string',
'kota' => 'required|string', 'kota' => 'required|string',
'kode_registrasi' => 'required'
]; ];
$request->validate($rules, ValidationRule::getErrorMessage($rules)); $request->validate($rules, ValidationRule::getErrorMessage($rules));
...@@ -60,7 +55,7 @@ public function store(Request $request) { ...@@ -60,7 +55,7 @@ public function store(Request $request) {
try{ try{
$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", 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;
...@@ -84,30 +79,51 @@ public function store(Request $request) { ...@@ -84,30 +79,51 @@ public function store(Request $request) {
$registrasi = Registrasi::query()->create($registrasi); $registrasi = Registrasi::query()->create($registrasi);
$id_registrasi = $registrasi->id; $id_registrasi = $registrasi->id;
//inisial harga //inisial harga
// dd($konaspi);
$totalHarga = (int) $konaspi->harga; $totalHarga = (int) $konaspi->harga;
foreach($request->konferensi as $kon){ if($request->konferensi[0] != null || $request->kegiatan0[0] != "498633a9-082c-4a4a-9dbd-e20b678ec15e"){
$i = 0; $i = 0;
$daftarKonferensi[] = $kon; foreach($request->konferensi as $kon){
$konferensi = Konferensi::query()->where('id', $kon)->first(); $daftarKonferensi[] = $kon;
$konferensi = Konferensi::query()->where('id', $kon)->first();
foreach($request->input('kegiatan'.$i) as $keg){
$daftarKegiatan[] = $keg; foreach($request->input('kegiatan'.$i) as $keg){
$kegiatan[] = Kegiatan::select('nama', 'harga')->where('id', $keg)->first(); $daftarKegiatan[] = $keg;
$kegiatan[] = Kegiatan::select('id', 'nama', 'harga')->where('id', $keg)->first();
}
$kegiatanpeserta[] = [
'id_registrasi' => $id_registrasi,
'id_kegiatan' => $kegiatan[$i]['id'],
'id_konferensi' => $daftarKonferensi[$i],
'nama_kegiatan' => $kegiatan[$i]['nama'],
'nama_konferensi' => $konferensi->nama,
'harga' => $kegiatan[$i]['harga']
];
$hargaKonferensi[] = [
'idkon' => $konferensi->id,
'namakon' => $konferensi->nama,
'hargakon' => $konferensi->harga,
'namakeg' => $kegiatan[$i]['nama']
];
$totalHarga += (int) $konferensi->harga;
$i++;
} }
$kegiatanpeserta[] = [ foreach($kegiatanpeserta as $keg){
KegiatanPeserta::query()->create($keg);
}
}
else{
$hargaKonferensi = null;
$kegiatanpeserta = [
'id_registrasi' => $id_registrasi, 'id_registrasi' => $id_registrasi,
'id_kegiatan' => $kon, 'id_kegiatan' => $request->kegiatan0[0],
'id_konferensi' => $daftarKonferensi[$i], 'id_konferensi' => null,
'nama_kegiatan' => $kegiatan[$i]['nama'],
'nama_konferensi' => $konferensi->nama,
'harga' => $kegiatan[$i]['harga']
]; ];
KegiatanPeserta::query()->create($kegiatanpeserta);
$totalHarga += (int) $konferensi->harga;
$i++;
} }
$multipartData = [ $multipartData = [
...@@ -135,17 +151,19 @@ public function store(Request $request) { ...@@ -135,17 +151,19 @@ public function store(Request $request) {
->with('error', 'Data failed to save'); ->with('error', 'Data failed to save');
} }
foreach($kegiatanpeserta as $keg){
KegiatanPeserta::query()->create($keg);
}
DB::commit(); DB::commit();
// return redirect()->back() // return redirect()->back()
// ->with('success', 'Data saved successfully'); // ->with('success', 'Data saved successfully');
// dd($kegiatanpeserta);
return view('invoice', compact('registrasi', 'tglRegistrasi', 'kegiatanpeserta'))->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){
...@@ -155,7 +173,6 @@ public function store(Request $request) { ...@@ -155,7 +173,6 @@ public function store(Request $request) {
return redirect()->back() return redirect()->back()
->with('error', 'Data failed to save'); ->with('error', 'Data failed to save');
} }
} }
private function generateVa($multipartData) private function generateVa($multipartData)
......
<div class="col-md-12" id="kegiatan-{{ $i }}"> <div class="col-md-12" id="kegiatan-{{ $i }}">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div class="form-group" id = "list-kegiatan" @if ($errors->has('thematic_workshop')) has-error @endif> <div class="form-group" id = "list-kegiatan" @if ($errors->has('nama-kegiatan-')) has-error @endif>
<label>Kegiatan</label> <label>Kegiatan</label>
<label>Untuk kegiatan konferensi bisa memilih lebih dari satu</label>
@foreach ($kegiatan as $j=>$keg) @foreach ($kegiatan as $j=>$keg)
<div class="form-check"> @php
<input class="form-check-input" type="radio" id="nama-kegiatan-{{ $i }}-{{ $j }}" name="kegiatan{{ $i }}[]" value="{{ $keg->id }}" onChange="cekKegiatan('nama-kegiatan-{{ $i }}-{{ $j }}')"> $idkeg = $keg->id;
<label class="form-check-label" for="{{ $keg->nama }}">{{ $keg->nama }}</label> @endphp
</div> @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>
</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>
</div>
@endif
@endforeach @endforeach
</div> </div>
<div class="form-group" id="grup-konferensi" @if ($errors->has('profil')) has-error @endif> <div class="form-group" id="grup-konferensi" @if ($errors->has('konferensi')) has-error @endif>
<label>Konferensi</label> <label>Konferensi</label>
<select class="form-control" id="konferensi" name="konferensi[]" required="true" placeholder=""> <select class="form-control" id="konferensi" name="konferensi[]"placeholder="">
<option value="" selected>- Pilih -</option> <option value="" selected>- Pilih -</option>
@foreach ($konferensi as $kon) @foreach ($konferensi as $kon)
<option onchange="cek(this.value)" value="{{ $kon->id }}">{{ $kon->nama }}</option> <option onchange="cek(this.value)" value="{{ $kon->id }}">{{ $kon->nama }}</option>
...@@ -22,9 +35,11 @@ ...@@ -22,9 +35,11 @@
<label id="login-error" class="error" for="konferensi" style="color: red">{{$errors->first('konferensi')}}</label> <label id="login-error" class="error" for="konferensi" style="color: red">{{$errors->first('konferensi')}}</label>
@endif @endif
</div> </div>
<div class="col-md-4 float-right"> @if ($i != 0)
<button class="btn btn-danger" type="button" onclick="hapusKegiatan('kegiatan-{{ $i }}')">Hapus</button> <div class="col-md-4 float-right">
</div> <button class="btn btn-danger" type="button" onclick="hapusKegiatan('kegiatan-{{ $i }}')">Hapus</button>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>
...@@ -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">
...@@ -116,17 +116,18 @@ ...@@ -116,17 +116,18 @@
]) }} ]) }}
</div> </div>
<div> <div>
<button type="button" class="btn btn-primary" onclick="tambahKegiatan()">Tambah kegiatan</button> <button type="button" class="btn btn-primary" onclick="tambahKegiatan()" name="tambah-kegiatan" id="tambah-kegiatan">Tambah kegiatan</button>
</div> </div>
<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>
...@@ -153,8 +154,14 @@ function cekKegiatan(id){ ...@@ -153,8 +154,14 @@ function cekKegiatan(id){
var value = document.getElementById(id).value; var value = document.getElementById(id).value;
if(value == '498633a9-082c-4a4a-9dbd-e20b678ec15e'){ if(value == '498633a9-082c-4a4a-9dbd-e20b678ec15e'){
$('#grup-konferensi').hide(); $('#grup-konferensi').hide();
$('#tambah-kegiatan').hide();
var konferensi = document.getElementById("konferensi");
konferensi.required = false;
} else { } else {
$('#grup-konferensi').show(); $('#grup-konferensi').show();
$('#tambah-kegiatan').show();
var konferensi = document.getElementById("konferensi");
konferensi.required = true;
} }
} }
...@@ -189,5 +196,9 @@ function tambahKegiatan(){ ...@@ -189,5 +196,9 @@ function tambahKegiatan(){
function hapusKegiatan(id){ function hapusKegiatan(id){
$('#'+id).remove(); $('#'+id).remove();
} }
function cekHarga(){
console.log('masuk');
}
</script> </script>
@endpush @endpush
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
<div class="col-md-6"> <div class="col-md-6">
<address> <address>
<strong>Metode Pembayaran:</strong><br> <strong>Metode Pembayaran:</strong><br>
Visa ending **** 4242<br> Virtual Account : <br>
{{$registrasi['email']}} {{-- {{$registrasi['email']}} --}}
</address> </address>
</div> </div>
<div class="col-md-6 text-md-right"> <div class="col-md-6 text-md-right">
...@@ -70,28 +70,40 @@ ...@@ -70,28 +70,40 @@
<th class="text-right">Total Harga</th> <th class="text-right">Total Harga</th>
</tr> </tr>
@php @php
$no = 1; $no = 2;
$subtotal = 0; $initialharga = $konaspi->harga;
$subtotal = $initialharga;
$i = 0; $i = 0;
@endphp @endphp
@foreach ($kegiatanpeserta as $keg)
@php
$subtotal = $subtotal + $keg['harga'];
@endphp
<tr> <tr>
<td>1</td> <td>1</td>
<td> <td>
{{$keg['nama_kegiatan']}} <br> Konferensi : <b> {{$keg['nama_konferensi']}} </b> Convention
</td> </td>
<td class="text-center">Rp {{$keg['harga']}}</td> <td class="text-center">Rp {{$konaspi->harga}}</td>
<td class="text-center">1</td> <td class="text-center">1</td>
<td class="text-right">Rp {{$keg['harga']}}</td> <td class="text-right">Rp {{$konaspi->harga}}</td>
</tr> </tr>
@php @if (isset($hargaKonferensi))
$i++; @foreach ($hargaKonferensi as $kon)
$no++; @php
@endphp $subtotal = $subtotal + $kon['hargakon'];
@endforeach @endphp
<tr>
<td>{{$no}}</td>
<td>
{{$kon['namakeg']}} <br> Konferensi : <b> {{$kon['namakon']}} </b>
</td>
<td class="text-center">Rp {{$kon['hargakon']}}</td>
<td class="text-center">1</td>
<td class="text-right">Rp {{$kon['hargakon']}}</td>
</tr>
@php
$i++;
$no++;
@endphp
@endforeach
@endif
</table> </table>
</div> </div>
<div class="row mt-4"> <div class="row mt-4">
...@@ -123,10 +135,10 @@ ...@@ -123,10 +135,10 @@
<hr> <hr>
<div class="text-md-right"> <div class="text-md-right">
<div class="float-lg-left mb-lg-0 mb-3"> <div class="float-lg-left mb-lg-0 mb-3">
<button class="btn btn-primary btn-icon icon-left"><i class="fas fa-credit-card"></i> Process Payment</button> <button class="btn btn-primary btn-icon icon-left"><i class="fas fa-credit-card"></i> Bayar</button>
<button class="btn btn-danger btn-icon icon-left"><i class="fas fa-times"></i> Cancel</button> <button class="btn btn-danger btn-icon icon-left"><i class="fas fa-times"></i> Cancel</button>
</div> </div>
<button class="btn btn-warning btn-icon icon-left"><i class="fas fa-print"></i> Print</button> <button class="btn btn-warning btn-icon icon-left"><i class="fas fa-print"></i> Cetak</button>
</div> </div>
</div> </div>
{{-- @endforeach --}} {{-- @endforeach --}}
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +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::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