Commit 1998f752 by Triyah Fatmawati

Perbaikan insert data

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