add anggota

parent 7a5e1c7e
......@@ -4,6 +4,7 @@
use App\Http\Support\ValidationRule;
use App\Jobs\SendMail;
use App\Models\Anggota;
use App\Models\Kegiatan;
use App\Models\KegiatanPeserta;
use App\Models\Konferensi;
......@@ -17,6 +18,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use RealRashid\SweetAlert\Facades\Alert;
use Str;
class RegistrasiController extends Controller
{
......@@ -70,18 +72,36 @@ public function group_create(){
}
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();
$konferensi = Konferensi::get();
$data = [
'kegiatan' => $kegiatan,
'konferensi' => $konferensi
'konferensi' => $konferensi,
'data_registrasi' => $request->except('_token'),
];
return view('form_kegiatan_kelompok', $data);
}
public function preview(Request $request){
//cek jika kelompok atau tidak
if(is_null($request->data_registrasi)){
$rules = [
'nama' => 'required|string',
'email' => 'required|email:rfc,dns',
......@@ -92,8 +112,8 @@ public function preview(Request $request){
'kodepos' => 'required|string',
'kota' => 'required|string',
];
$request->validate($rules, ValidationRule::getErrorMessage($rules));
}
DB::beginTransaction();
......@@ -110,6 +130,10 @@ public function preview(Request $request){
$nourut = sprintf("%05s", $urutan);
$kode_registrasi = $nourut;
if(!is_null($request->data_registrasi)){
$registrasi = json_decode(decrypt($request->data_registrasi), true);
}
else{
$registrasi = [
'nama' => strip_tags($request->nama),
'email' => strip_tags($request->email),
......@@ -123,6 +147,7 @@ public function preview(Request $request){
'urutan' => $urutan,
'nik' => strip_tags($request->nik)
];
}
$tglRegistrasi = Carbon::now()->format('Y-m-d h:i:s');
$konaspi = Kegiatan::query()->where('id', '498633a9-082c-4a4a-9dbd-e20b678ec15e')->first();
......@@ -130,15 +155,19 @@ public function preview(Request $request){
//inisial 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;
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('id', 'nama', 'harga')->where('id', $keg)->first();
$daftarKegiatan[] = $request->kegiatan[$i];
$kegiatan[] = Kegiatan::select('id', 'nama', 'harga')->where('id', $request->kegiatan[$i])->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[] = [
......@@ -146,14 +175,16 @@ public function preview(Request $request){
'id_konferensi' => $daftarKonferensi[$i],
'nama_kegiatan' => $kegiatan[$i]['nama'],
'nama_konferensi' => $konferensi->nama,
'harga' => $kegiatan[$i]['harga']
'harga' => $kegiatan[$i]['harga'],
'anggota' => $kegiatanAnggota
];
$hargaKonferensi[] = [
'idkon' => $konferensi->id,
'namakon' => $konferensi->nama,
'hargakon' => $konferensi->harga,
'namakeg' => $kegiatan[$i]['nama']
'namakeg' => $kegiatan[$i]['nama'],
'anggota' => $kegiatanAnggota
];
// $totalHarga += (int) $konferensi->harga;
......@@ -174,7 +205,8 @@ public function preview(Request $request){
'tglRegistrasi' => $tglRegistrasi,
'konaspi' => $konaspi,
'hargaKonferensi' => $hargaKonferensi,
'totalHarga' => $totalHarga
'totalHarga' => $totalHarga,
'anggota' => $request->anggota ?? [],
];
return view('preview', $data)->with('success', 'Data saved successfully');
......@@ -183,8 +215,8 @@ public function preview(Request $request){
catch(Exception $e){
Log::error($e);
DB::rollBack();
return redirect()->route('user.create')
dd($e);
return redirect()->back()
->with('error', 'Data failed to save');
}
}
......@@ -197,11 +229,17 @@ public function store(Request $request) {
$kegiatanpeserta = json_decode($request->kegiatanpeserta, true);
$konaspi = json_decode($request->konaspi, true);
$hargaKonferensi = json_decode($request->hargaKonferensi, true);
$anggota = json_decode($request->anggota, true);
$tglRegistrasi = $request->tglRegistrasi;
// $totalHargas = $request->totalHarga;
foreach($anggota as $key => $item){
$anggota[$key]['id'] = Str::uuid()->toString();
}
// Anggota::query()->insert($anggota);
$registrasi = Registrasi::query()->create($registrasi);
$id_registrasi = $registrasi->id;
// $registrasi = Registrasi::query()->create($registrasi);
// $id_registrasi = $registrasi->id;
$id_registrasi = '$registrasi->id';
$jumlahKeg = count($kegiatanpeserta);
//inisial harga
......@@ -210,12 +248,24 @@ public function store(Request $request) {
$totalHarga = (int) $konvensi->harga;
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 = [
'id_registrasi' => $id_registrasi,
'id_kegiatan' => $keg['id_kegiatan'],
'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'){
$konferensi = Konferensi::query()->where('id', $keg['id_konferensi'])->first();
......@@ -233,7 +283,7 @@ public function store(Request $request) {
$kegPeserta = null;
}
}
dd('');
$multipartData = [
'noid' => $registrasi['kode_registrasi'],
'nama' => $registrasi['nama'],
......@@ -281,6 +331,8 @@ public function store(Request $request) {
Log::error($e);
DB::rollBack();
dd($e);
return redirect()->route('user.create')
->with('error', 'Data failed to save');
}
......@@ -319,16 +371,23 @@ public function addFormKegiatan(Request $request)
$data['kegiatan'] = Kegiatan::get();
$data['konferensi'] = Konferensi::get();
$data['i'] = $request->i;
$data['anggota'] = $request->anggota;
$data['list_anggota'] = $request->list_anggota;
return view('form_kegiatan', $data);
}
public function addFormAnggota(Request $request)
{
$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)
......
<?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
'id',
'id_registrasi',
'id_kegiatan',
'id_konferensi'
'id_konferensi',
'id_anggota'
];
public function rRegistrasi() {
......
......@@ -11,13 +11,13 @@
@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 }}')" 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>
</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 }}')" 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>
</div>
@endif
......@@ -25,7 +25,7 @@
</div>
<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[]"placeholder="">
<select class="form-control" id="konferensi" name="konferensi[{{ $i }}]"placeholder="">
<option value="" selected>- Pilih -</option>
@foreach ($konferensi as $kon)
<option onchange="cek(this.value)" value="{{ $kon->id }}">{{ $kon->nama }}</option>
......@@ -35,6 +35,23 @@
<label id="login-error" class="error" for="konferensi" style="color: red">{{$errors->first('konferensi')}}</label>
@endif
</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)
<div class="col-md-4 float-right">
<button class="btn btn-danger" type="button" onclick="hapusKegiatan('kegiatan-{{ $i }}')">Hapus</button>
......
......@@ -73,6 +73,7 @@
$initialharga = $konaspi->harga;
$subtotal = $initialharga;
$i = 0;
$jumlahAnggota = count($anggota) > 0 ? count($anggota) : 1;
@endphp
<tr>
<td>1</td>
......@@ -80,8 +81,8 @@
Convention
</td>
<td class="text-center">Rp {{$konaspi->harga}}</td>
<td class="text-center">1</td>
<td class="text-right">Rp {{$konaspi->harga}}</td>
<td class="text-center">{{ $jumlahAnggota }}</td>
<td class="text-right">Rp {{$konaspi->harga * $jumlahAnggota}}</td>
</tr>
@if (isset($hargaKonferensi))
@foreach ($hargaKonferensi as $kon)
......@@ -91,7 +92,12 @@
<tr>
<td>{{$no}}</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 class="text-center">Rp {{$kon['hargakon']}}</td> --}}
<td class="text-center">-</td>
......@@ -122,13 +128,13 @@
<div class="invoice-detail-item">
<div class="invoice-detail-name">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>
<hr class="mt-2 mb-2">
<div class="invoice-detail-item">
<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 {{$konaspi->harga}}</div>
<div class="invoice-detail-value invoice-detail-value-lg">Rp {{$konaspi->harga * $jumlahAnggota}}</div>
</div>
</div>
</div>
......@@ -148,6 +154,7 @@
<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="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 class="btn btn-danger btn-icon icon-left"><i class="fas fa-times"></i> Cancel</button>
</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