add anggota

parent 7a5e1c7e
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
use App\Http\Support\ValidationRule; use App\Http\Support\ValidationRule;
use App\Jobs\SendMail; use App\Jobs\SendMail;
use App\Models\Anggota;
use App\Models\Kegiatan; use App\Models\Kegiatan;
use App\Models\KegiatanPeserta; use App\Models\KegiatanPeserta;
use App\Models\Konferensi; use App\Models\Konferensi;
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
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; use RealRashid\SweetAlert\Facades\Alert;
use Str;
class RegistrasiController extends Controller class RegistrasiController extends Controller
{ {
...@@ -70,18 +72,36 @@ public function group_create(){ ...@@ -70,18 +72,36 @@ public function group_create(){
} }
public function group_kegiatan(Request $request){ public function group_kegiatan(Request $request){
$rules = [
'nama' => 'required|string',
'email' => 'required|email:rfc,dns',
'telepon' => 'required|numeric',
'instansi' => 'required|string',
'jabatan' => 'required|string',
'alamat' => 'required|string',
'kodepos' => 'required|string',
'kota' => 'required|string',
'nik' => 'required|unique:registrasi,nik'
];
$request->validate($rules, ValidationRule::getErrorMessage($rules));
$kegiatan = Kegiatan::orderBy('id')->get(); $kegiatan = Kegiatan::orderBy('id')->get();
$konferensi = Konferensi::get(); $konferensi = Konferensi::get();
$data = [ $data = [
'kegiatan' => $kegiatan, 'kegiatan' => $kegiatan,
'konferensi' => $konferensi 'konferensi' => $konferensi,
'data_registrasi' => $request->except('_token'),
]; ];
return view('form_kegiatan_kelompok', $data); return view('form_kegiatan_kelompok', $data);
} }
public function preview(Request $request){ public function preview(Request $request){
//cek jika kelompok atau tidak
if(is_null($request->data_registrasi)){
$rules = [ $rules = [
'nama' => 'required|string', 'nama' => 'required|string',
'email' => 'required|email:rfc,dns', 'email' => 'required|email:rfc,dns',
...@@ -92,8 +112,8 @@ public function preview(Request $request){ ...@@ -92,8 +112,8 @@ public function preview(Request $request){
'kodepos' => 'required|string', 'kodepos' => 'required|string',
'kota' => 'required|string', 'kota' => 'required|string',
]; ];
$request->validate($rules, ValidationRule::getErrorMessage($rules)); $request->validate($rules, ValidationRule::getErrorMessage($rules));
}
DB::beginTransaction(); DB::beginTransaction();
...@@ -110,6 +130,10 @@ public function preview(Request $request){ ...@@ -110,6 +130,10 @@ public function preview(Request $request){
$nourut = sprintf("%05s", $urutan); $nourut = sprintf("%05s", $urutan);
$kode_registrasi = $nourut; $kode_registrasi = $nourut;
if(!is_null($request->data_registrasi)){
$registrasi = json_decode(decrypt($request->data_registrasi), true);
}
else{
$registrasi = [ $registrasi = [
'nama' => strip_tags($request->nama), 'nama' => strip_tags($request->nama),
'email' => strip_tags($request->email), 'email' => strip_tags($request->email),
...@@ -123,6 +147,7 @@ public function preview(Request $request){ ...@@ -123,6 +147,7 @@ public function preview(Request $request){
'urutan' => $urutan, 'urutan' => $urutan,
'nik' => strip_tags($request->nik) 'nik' => strip_tags($request->nik)
]; ];
}
$tglRegistrasi = Carbon::now()->format('Y-m-d h:i:s'); $tglRegistrasi = Carbon::now()->format('Y-m-d h:i:s');
$konaspi = Kegiatan::query()->where('id', '498633a9-082c-4a4a-9dbd-e20b678ec15e')->first(); $konaspi = Kegiatan::query()->where('id', '498633a9-082c-4a4a-9dbd-e20b678ec15e')->first();
...@@ -130,15 +155,19 @@ public function preview(Request $request){ ...@@ -130,15 +155,19 @@ public function preview(Request $request){
//inisial harga //inisial harga
$totalHarga = (int) $konaspi->harga; $totalHarga = (int) $konaspi->harga;
if($request->konferensi[0] != null || $request->kegiatan0[0] != "498633a9-082c-4a4a-9dbd-e20b678ec15e"){ if($request->konferensi[0] != null || $request->kegiatan[0] != "498633a9-082c-4a4a-9dbd-e20b678ec15e"){
$i = 0; $i = 0;
foreach($request->konferensi as $kon){ foreach($request->konferensi as $kon){
$daftarKonferensi[] = $kon; $daftarKonferensi[] = $kon;
$konferensi = Konferensi::query()->where('id', $kon)->first(); $konferensi = Konferensi::query()->where('id', $kon)->first();
foreach($request->input('kegiatan'.$i) as $keg){ $daftarKegiatan[] = $request->kegiatan[$i];
$daftarKegiatan[] = $keg; $kegiatan[] = Kegiatan::select('id', 'nama', 'harga')->where('id', $request->kegiatan[$i])->first();
$kegiatan[] = Kegiatan::select('id', 'nama', 'harga')->where('id', $keg)->first(); $indexAnggota = isset($request->kegiatan_anggota[$i]) ? $request->kegiatan_anggota[$i] : null;
$kegiatanAnggota = !is_null($indexAnggota) ? $request->anggota[$indexAnggota] : [];
if(!empty($kegiatanAnggota)){
$kegiatanAnggota['key'] = $request->kegiatan_anggota[$i];
} }
$kegiatanpeserta[] = [ $kegiatanpeserta[] = [
...@@ -146,14 +175,16 @@ public function preview(Request $request){ ...@@ -146,14 +175,16 @@ public function preview(Request $request){
'id_konferensi' => $daftarKonferensi[$i], 'id_konferensi' => $daftarKonferensi[$i],
'nama_kegiatan' => $kegiatan[$i]['nama'], 'nama_kegiatan' => $kegiatan[$i]['nama'],
'nama_konferensi' => $konferensi->nama, 'nama_konferensi' => $konferensi->nama,
'harga' => $kegiatan[$i]['harga'] 'harga' => $kegiatan[$i]['harga'],
'anggota' => $kegiatanAnggota
]; ];
$hargaKonferensi[] = [ $hargaKonferensi[] = [
'idkon' => $konferensi->id, 'idkon' => $konferensi->id,
'namakon' => $konferensi->nama, 'namakon' => $konferensi->nama,
'hargakon' => $konferensi->harga, 'hargakon' => $konferensi->harga,
'namakeg' => $kegiatan[$i]['nama'] 'namakeg' => $kegiatan[$i]['nama'],
'anggota' => $kegiatanAnggota
]; ];
// $totalHarga += (int) $konferensi->harga; // $totalHarga += (int) $konferensi->harga;
...@@ -174,7 +205,8 @@ public function preview(Request $request){ ...@@ -174,7 +205,8 @@ public function preview(Request $request){
'tglRegistrasi' => $tglRegistrasi, 'tglRegistrasi' => $tglRegistrasi,
'konaspi' => $konaspi, 'konaspi' => $konaspi,
'hargaKonferensi' => $hargaKonferensi, 'hargaKonferensi' => $hargaKonferensi,
'totalHarga' => $totalHarga 'totalHarga' => $totalHarga,
'anggota' => $request->anggota ?? [],
]; ];
return view('preview', $data)->with('success', 'Data saved successfully'); return view('preview', $data)->with('success', 'Data saved successfully');
...@@ -183,8 +215,8 @@ public function preview(Request $request){ ...@@ -183,8 +215,8 @@ public function preview(Request $request){
catch(Exception $e){ catch(Exception $e){
Log::error($e); Log::error($e);
DB::rollBack(); DB::rollBack();
dd($e);
return redirect()->route('user.create') return redirect()->back()
->with('error', 'Data failed to save'); ->with('error', 'Data failed to save');
} }
} }
...@@ -197,11 +229,17 @@ public function store(Request $request) { ...@@ -197,11 +229,17 @@ public function store(Request $request) {
$kegiatanpeserta = json_decode($request->kegiatanpeserta, true); $kegiatanpeserta = json_decode($request->kegiatanpeserta, true);
$konaspi = json_decode($request->konaspi, true); $konaspi = json_decode($request->konaspi, true);
$hargaKonferensi = json_decode($request->hargaKonferensi, true); $hargaKonferensi = json_decode($request->hargaKonferensi, true);
$anggota = json_decode($request->anggota, true);
$tglRegistrasi = $request->tglRegistrasi; $tglRegistrasi = $request->tglRegistrasi;
// $totalHargas = $request->totalHarga; // $totalHargas = $request->totalHarga;
foreach($anggota as $key => $item){
$anggota[$key]['id'] = Str::uuid()->toString();
}
// Anggota::query()->insert($anggota);
$registrasi = Registrasi::query()->create($registrasi); // $registrasi = Registrasi::query()->create($registrasi);
$id_registrasi = $registrasi->id; // $id_registrasi = $registrasi->id;
$id_registrasi = '$registrasi->id';
$jumlahKeg = count($kegiatanpeserta); $jumlahKeg = count($kegiatanpeserta);
//inisial harga //inisial harga
...@@ -210,12 +248,24 @@ public function store(Request $request) { ...@@ -210,12 +248,24 @@ public function store(Request $request) {
$totalHarga = (int) $konvensi->harga; $totalHarga = (int) $konvensi->harga;
foreach($kegiatanpeserta as $keg){ foreach($kegiatanpeserta as $keg){
$arrayKeg = $keg;
if(isset($arrayKeg['anggota']['key'])){
$idPeserta = isset($anggota[$arrayKeg['anggota']['key']]['id']) ? $anggota[$keg['anggota']['key']]['id'] : null;
}
else{
$idPeserta = null;
}
$kegpeserta = [ $kegpeserta = [
'id_registrasi' => $id_registrasi, 'id_registrasi' => $id_registrasi,
'id_kegiatan' => $keg['id_kegiatan'], 'id_kegiatan' => $keg['id_kegiatan'],
'id_konferensi' => $keg['id_konferensi'], 'id_konferensi' => $keg['id_konferensi'],
'id_anggota' => $idPeserta
// 'id_anggota' =>
]; ];
KegiatanPeserta::query()->create($kegpeserta); dd($kegpeserta);
// KegiatanPeserta::query()->create($kegpeserta);
if($keg['id_kegiatan'] != '498633a9-082c-4a4a-9dbd-e20b678ec15e'){ if($keg['id_kegiatan'] != '498633a9-082c-4a4a-9dbd-e20b678ec15e'){
$konferensi = Konferensi::query()->where('id', $keg['id_konferensi'])->first(); $konferensi = Konferensi::query()->where('id', $keg['id_konferensi'])->first();
...@@ -233,7 +283,7 @@ public function store(Request $request) { ...@@ -233,7 +283,7 @@ public function store(Request $request) {
$kegPeserta = null; $kegPeserta = null;
} }
} }
dd('');
$multipartData = [ $multipartData = [
'noid' => $registrasi['kode_registrasi'], 'noid' => $registrasi['kode_registrasi'],
'nama' => $registrasi['nama'], 'nama' => $registrasi['nama'],
...@@ -281,6 +331,8 @@ public function store(Request $request) { ...@@ -281,6 +331,8 @@ public function store(Request $request) {
Log::error($e); Log::error($e);
DB::rollBack(); DB::rollBack();
dd($e);
return redirect()->route('user.create') return redirect()->route('user.create')
->with('error', 'Data failed to save'); ->with('error', 'Data failed to save');
} }
...@@ -319,16 +371,23 @@ public function addFormKegiatan(Request $request) ...@@ -319,16 +371,23 @@ public function addFormKegiatan(Request $request)
$data['kegiatan'] = Kegiatan::get(); $data['kegiatan'] = Kegiatan::get();
$data['konferensi'] = Konferensi::get(); $data['konferensi'] = Konferensi::get();
$data['i'] = $request->i; $data['i'] = $request->i;
$data['anggota'] = $request->anggota;
$data['list_anggota'] = $request->list_anggota;
return view('form_kegiatan', $data); return view('form_kegiatan', $data);
} }
public function addFormAnggota(Request $request) public function addFormAnggota(Request $request)
{ {
$data['i'] = $request->i; $data['i'] = $request->i;
$data['item'] = [
'nama' => $request->nama,
'email' => $request->email,
'nik' => $request->nik,
'telepon' => $request->telepon,
];
return view('form_anggota_kelompok', $data); return view('row_anggota', $data);
} }
public function getDataRegis($va) public function getDataRegis($va)
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Anggota extends Model
{
use HasFactory;
public $incrementing = false;
protected $table = 'anggota';
protected $keyType = 'string';
protected $fillable = [
'id',
'id_registrasi',
'nama',
'email',
'telepon',
'nik'
];
}
...@@ -19,7 +19,8 @@ class KegiatanPeserta extends Model ...@@ -19,7 +19,8 @@ class KegiatanPeserta extends Model
'id', 'id',
'id_registrasi', 'id_registrasi',
'id_kegiatan', 'id_kegiatan',
'id_konferensi' 'id_konferensi',
'id_anggota'
]; ];
public function rRegistrasi() { public function rRegistrasi() {
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
@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 }}')" required> <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> <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 }}')" required> <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> <label class="form-check-label" for="nama-kegiatan-{{ $i }}-{{ $j }}">{{ $keg->nama }}</label>
</div> </div>
@endif @endif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</div> </div>
<div class="form-group" id="grup-konferensi" @if ($errors->has('konferensi')) 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[]"placeholder=""> <select class="form-control" id="konferensi" name="konferensi[{{ $i }}]"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>
...@@ -35,6 +35,23 @@ ...@@ -35,6 +35,23 @@
<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>
@if (isset($anggota))
<label>Anggota</label>
<select class="form-control anggota-select" id="" name="kegiatan_anggota[{{ $i }}]"placeholder="">
<option value="" selected>- Pilih -</option>
@foreach (json_decode($list_anggota, true) as $key => $item)
<option value="{{ $key }}">
{{ $item['nama'] }}
:
{{ $item['email'] }}
</option>
@endforeach
</select>
@if ($errors->has('anggota'))
<label id="login-error" class="error" for="konferensi" style="color: red">{{$errors->first('konferensi')}}</label>
@endif
@endif
<br>
@if ($i != 0) @if ($i != 0)
<div class="col-md-4 float-right"> <div class="col-md-4 float-right">
<button class="btn btn-danger" type="button" onclick="hapusKegiatan('kegiatan-{{ $i }}')">Hapus</button> <button class="btn btn-danger" type="button" onclick="hapusKegiatan('kegiatan-{{ $i }}')">Hapus</button>
......
...@@ -8,24 +8,25 @@ ...@@ -8,24 +8,25 @@
</div> </div>
</div> </div>
<form class="needs-validation" novalidate="" method="POST" action="{{ route('user.preview')}}" enctype="multipart/form-data">
<div class="section-body"> <div class="section-body">
<form class="needs-validation" novalidate="" method="POST" action="{{ route('user.preview')}}" enctype="multipart/form-data">
@csrf @csrf
<div class="row"> <div class="row">
<div class="col-12 col-md-8 col-lg-8"> <div class="col-12 col-md-8 col-lg-8">
<div class="card"> <div class="card">
<div class="card-body" id="parent-anggota"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-6 form-group" @if ($errors->has('nama')) has-error @endif> <div class="col-6 form-group" @if ($errors->has('nama')) has-error @endif>
<label>Nama</label> <label>Nama</label>
<input type="text" id="nama" name="nama" class="form-control" required="" placeholder="" value="{{ old('nama')}}"> <input type="text" id="nama_anggota" class="form-control" placeholder="" value="{{ old('nama')}}">
@if ($errors->has('nama')) @if ($errors->has('nama'))
<label id="login-error" class="error" for="nama" style="color: red">{{$errors->first('nama')}}</label> <label id="login-error" class="error" for="nama" style="color: red">{{$errors->first('nama')}}</label>
@endif @endif
</div> </div>
<div class="col-6 form-group" @if ($errors->has('nik')) has-error @endif> <div class="col-6 form-group" @if ($errors->has('nik')) has-error @endif>
<label>NIK</label> <label>NIK</label>
<input type="text" id="nik" name="nik" class="form-control" required="" placeholder="" value="{{ old('nik')}}"> <input type="text" id="nik_anggota" class="form-control" placeholder="" value="{{ old('nik')}}">
@if ($errors->has('nik')) @if ($errors->has('nik'))
<label id="login-error" class="error" for="nik" style="color: red">{{$errors->first('nik')}}</label> <label id="login-error" class="error" for="nik" style="color: red">{{$errors->first('nik')}}</label>
@endif @endif
...@@ -40,7 +41,7 @@ ...@@ -40,7 +41,7 @@
<i class="fas fa-envelope"></i> <i class="fas fa-envelope"></i>
</div> </div>
</div> </div>
<input type="email" id="email" name="email" class="form-control email" required="" placeholder="" value="{{ old('email')}}"> <input type="email" id="email_anggota" class="form-control email" placeholder="" value="{{ old('email')}}">
</div> </div>
@if ($errors->has('email')) @if ($errors->has('email'))
<label id="login-error" class="error" for="nama_depan" style="color: red">{{$errors->first('email')}}</label> <label id="login-error" class="error" for="nama_depan" style="color: red">{{$errors->first('email')}}</label>
...@@ -54,7 +55,7 @@ ...@@ -54,7 +55,7 @@
<i class="fas fa-phone"></i> <i class="fas fa-phone"></i>
</div> </div>
</div> </div>
<input type="number" id="telepon" name="telepon" class="form-control number" required="true" placeholder="" value="{{ old('telepon')}}"> <input type="number" id="telepon_anggota" class="form-control number" placeholder="" value="{{ old('telepon')}}">
</div> </div>
@if ($errors->has('telepon')) @if ($errors->has('telepon'))
<label id="login-error" class="error" for="telepon" style="color: red">{{$errors->first('telepon')}}</label> <label id="login-error" class="error" for="telepon" style="color: red">{{$errors->first('telepon')}}</label>
...@@ -66,27 +67,52 @@ ...@@ -66,27 +67,52 @@
<div> <div>
<button type="button" class="btn btn-primary" onclick="tambahAnggota()" name="tambah-anggota" id="tambah-anggota">Tambah Anggota</button> <button type="button" class="btn btn-primary" onclick="tambahAnggota()" name="tambah-anggota" id="tambah-anggota">Tambah Anggota</button>
</div> </div>
<br>
<h5>Anggota</h5>
<span class="badge badge-warning"><i class="fa fa-info"></i> &nbsp; Setiap anggota yang ditambahkan akan terdaftar sebagai peserta konvensi</span>
<br>
<br>
<div class="card">
<div class="card-body">
<table class="table table-responsive">
<thead>
<tr>
<th>No.</th>
<th>Nama</th>
<th>Email</th>
<th>Nik</th>
<th>Telepon</th>
<th></th>
</tr>
</thead>
<tbody id="parent-anggota">
{!! view('row_anggota', [
'i' => 1,
'item' => $data_registrasi
]) !!}
</tbody>
</table>
</div>
</div>
</div> </div>
<div class="col-12 col-md-4 col-lg-4"> <div class="col-12 col-md-4 col-lg-4">
<input type="hidden" name="data_registrasi" value="{{ encrypt(json_encode($data_registrasi, true)) }}">
<p class="alert alert-info"><i class="fa fa-info"></i> &nbsp; Klik tambah konferensi jika ingin mengikuti konferensi dan pilih konferensi yang diinginkan untuk setiap anggota</p>
<br>
<br>
<div class="row" id="parent-kegiatan"> <div class="row" id="parent-kegiatan">
{{ view('form_kegiatan', [
'kegiatan' => $kegiatan,
'konferensi' => $konferensi,
'i' => 0
]) }}
</div> </div>
<div> <div>
<button type="button" class="btn btn-primary" onclick="tambahKegiatan()" name="tambah-kegiatan" id="tambah-kegiatan">Tambah kegiatan</button> <button type="button" class="btn btn-primary" onclick="tambahKegiatan()" name="tambah-kegiatan" id="tambah-kegiatan">Tambah Konferensi</button>
</div> </div>
<hr> <hr>
</div> </div>
</div> </div>
<div class="card-footer text-right"> <div class="card-footer text-right">
<button class="btn btn-primary mr-1" type="submit">Daftar</button> <button class="btn btn-primary mr-1" type="submit">Daftar</button>
<button class="btn btn-secondary" type="reset">Reset</button>
</div>
</div> </div>
</form> </form>
</div>
</section> </section>
@endsection @endsection
...@@ -118,19 +144,29 @@ function cekKegiatan(id){ ...@@ -118,19 +144,29 @@ function cekKegiatan(id){
</script> </script>
<script> <script>
var i = 1; let anggota = {};
anggota[1] = {
nama:'{{ $data_registrasi['nama'] }}',
nik:'{{ $data_registrasi['nik'] }}',
email:'{{ $data_registrasi['email'] }}',
telepon:'{{ $data_registrasi['telepon'] }}'
};
var i = 0;
function tambahKegiatan(){ function tambahKegiatan(){
let token = '{{ csrf_token() }}'; let token = '{{ csrf_token() }}';
if (i === undefined) { if (i === undefined) {
i = 1; i = 1;
} }
let list_anggota = JSON.stringify(anggota);
var request = $.ajax({ var request = $.ajax({
url: '{{ route('registrasi.form-kegiatan.add') }}', url: '{{ route('registrasi.form-kegiatan.add') }}',
type:'POST', type:'POST',
dataType: 'html', dataType: 'html',
data: {_token:token, i:i}, data: {_token:token, i:i, anggota:true, list_anggota:list_anggota},
success: function (result) { success: function (result) {
$('#parent-kegiatan').append(result); $('#parent-kegiatan').append(result);
}, },
...@@ -146,32 +182,66 @@ function tambahKegiatan(){ ...@@ -146,32 +182,66 @@ function tambahKegiatan(){
function hapusKegiatan(id){ function hapusKegiatan(id){
$('#'+id).remove(); $('#'+id).remove();
} }
</script>
<script> var iA = 2;
var i = 1;
function tambahAnggota(){
let token = '{{ csrf_token() }}';
if (i === undefined) { function tambahAnggota()
i = 1; {
} let token = '{{ csrf_token() }}';
var request = $.ajax({ var request = $.ajax({
url: '{{ route('registrasi.form-anggota.add') }}', url: '{{ route('registrasi.form-anggota.add') }}',
type:'POST', type:'POST',
dataType: 'html', dataType: 'html',
data: {_token:token, i:i}, data: {
_token:token,
i:iA,
nama:$('#nama_anggota').val(),
nik:$('#nik_anggota').val(),
email:$('#email_anggota').val(),
telepon:$('#telepon_anggota').val(),
},
success: function (result) { success: function (result) {
$('#parent-anggota').append(result); $('#parent-anggota').append(result);
anggota[iA] = {
nama: $('#nama_anggota').val(),
nik: $('#nik_anggota').val(),
email: $('#email_anggota').val(),
telepon: $('#telepon_anggota').val(),
};
addOptionToSelects(iA, $('#nama_anggota').val() + ' : ' + $('#email_anggota').val());
$('#nama_anggota').val('');
$('#nik_anggota').val('');
$('#email_anggota').val('');
$('#telepon_anggota').val('');
console.log(anggota);
iA++;
}, },
error: function(error) { error: function(error) {
alert('periksa koneksi anda'); alert('periksa koneksi anda');
} }
}); });
}
i++; function addOptionToSelects(key, name) {
$('.anggota-select').each(function() {
$(this).append(new Option(name, key));
});
}
function hapusAnggota(id)
{
$('#anggota-'+id).remove();
delete anggota[id];
$('.anggota-select').each(function() {
$(this).find('option[value='+id+']').remove();
});
} }
function hapusKegiatan(id){ function hapusKegiatan(id){
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
$initialharga = $konaspi->harga; $initialharga = $konaspi->harga;
$subtotal = $initialharga; $subtotal = $initialharga;
$i = 0; $i = 0;
$jumlahAnggota = count($anggota) > 0 ? count($anggota) : 1;
@endphp @endphp
<tr> <tr>
<td>1</td> <td>1</td>
...@@ -80,8 +81,8 @@ ...@@ -80,8 +81,8 @@
Convention Convention
</td> </td>
<td class="text-center">Rp {{$konaspi->harga}}</td> <td class="text-center">Rp {{$konaspi->harga}}</td>
<td class="text-center">1</td> <td class="text-center">{{ $jumlahAnggota }}</td>
<td class="text-right">Rp {{$konaspi->harga}}</td> <td class="text-right">Rp {{$konaspi->harga * $jumlahAnggota}}</td>
</tr> </tr>
@if (isset($hargaKonferensi)) @if (isset($hargaKonferensi))
@foreach ($hargaKonferensi as $kon) @foreach ($hargaKonferensi as $kon)
...@@ -91,7 +92,12 @@ ...@@ -91,7 +92,12 @@
<tr> <tr>
<td>{{$no}}</td> <td>{{$no}}</td>
<td> <td>
{{$kon['namakeg']}} <br> Konferensi : <b> {{$kon['namakon']}} </b> {{$kon['namakeg']}}
<br>Konferensi : <b> {{$kon['namakon']}} </b>
@isset($kon['anggota']['nama'])
<br>Anggota : <b>{{ $kon['anggota']['nama'] }}</b>
@endisset
</td> </td>
{{-- <td class="text-center">Rp {{$kon['hargakon']}}</td> --}} {{-- <td class="text-center">Rp {{$kon['hargakon']}}</td> --}}
<td class="text-center">-</td> <td class="text-center">-</td>
...@@ -122,13 +128,13 @@ ...@@ -122,13 +128,13 @@
<div class="invoice-detail-item"> <div class="invoice-detail-item">
<div class="invoice-detail-name">Subtotal</div> <div class="invoice-detail-name">Subtotal</div>
{{-- <div class="invoice-detail-value">Rp {{$subtotal}}</div> --}} {{-- <div class="invoice-detail-value">Rp {{$subtotal}}</div> --}}
<div class="invoice-detail-value">Rp {{$konaspi->harga}}</div> <div class="invoice-detail-value">Rp {{$konaspi->harga * $jumlahAnggota}}</div>
</div> </div>
<hr class="mt-2 mb-2"> <hr class="mt-2 mb-2">
<div class="invoice-detail-item"> <div class="invoice-detail-item">
<div class="invoice-detail-name">Total</div> <div class="invoice-detail-name">Total</div>
{{-- <div class="invoice-detail-value invoice-detail-value-lg">Rp {{$subtotal}}</div> --}} {{-- <div class="invoice-detail-value invoice-detail-value-lg">Rp {{$subtotal}}</div> --}}
<div class="invoice-detail-value invoice-detail-value-lg">Rp {{$konaspi->harga}}</div> <div class="invoice-detail-value invoice-detail-value-lg">Rp {{$konaspi->harga * $jumlahAnggota}}</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -148,6 +154,7 @@ ...@@ -148,6 +154,7 @@
<input type="hidden" id="konaspi" name="konaspi" value="{{ json_encode($konaspi) }}"> <input type="hidden" id="konaspi" name="konaspi" value="{{ json_encode($konaspi) }}">
<input type="hidden" id="hargaKonferensi" name="hargaKonferensi" value="{{ json_encode($hargaKonferensi) }}"> <input type="hidden" id="hargaKonferensi" name="hargaKonferensi" value="{{ json_encode($hargaKonferensi) }}">
<input type="hidden" id="totalHarga" name="totalHarga" value="{{ json_encode($totalHarga) }}"> <input type="hidden" id="totalHarga" name="totalHarga" value="{{ json_encode($totalHarga) }}">
<input type="hidden" id="totalHarga" name="anggota" value="{{ json_encode($anggota) }}">
<button type="submit" class="btn btn-primary btn-icon icon-left"><i class="fas fa-credit-card"></i> Daftar</button> <button type="submit" class="btn btn-primary btn-icon icon-left"><i class="fas fa-credit-card"></i> Daftar</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>
......
<tr id="anggota-{{ $i }}">
<td>
{{ $i }}
</td>
<td>
{{ $item['nama'] }}
<input type="hidden" name="anggota[{{ $i }}][nama]" value="{{ $item['nama'] }}" required/>
</td>
<td>
{{ $item['email'] }}
<input type="hidden" name="anggota[{{ $i }}][email]" value="{{ $item['email'] }}" required/>
</td>
<td>
{{ $item['nik'] }}
<input type="hidden" name="anggota[{{ $i }}][nik]" value="{{ $item['nik'] }}" required/>
</td>
<td>
{{ $item['telepon'] }}
<input type="hidden" name="anggota[{{ $i }}][telepon]" value="{{ $item['telepon'] }}" required/>
</td>
<td>
@if ($i > 1)
<div class="col-md-4 float-right">
<button class="btn btn-danger" type="button" onclick="hapusAnggota('{{ $i }}')">Hapus</button>
</div>
@endif
</td>
</tr>
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