Commit f4473869 by Triyah Fatmawati

penyesuaian banyak kegiatan

parent e018b413
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
use App\Http\Support\ValidationRule; use App\Http\Support\ValidationRule;
use App\Models\Kegiatan; use App\Models\Kegiatan;
use App\Models\KegiatanPeserta;
use App\Models\Konferensi; use App\Models\Konferensi;
use App\Models\Registrasi; use App\Models\Registrasi;
use Carbon\Carbon; use Carbon\Carbon;
...@@ -35,6 +36,7 @@ public function create(){ ...@@ -35,6 +36,7 @@ public function create(){
} }
public function store(Request $request) { public function store(Request $request) {
// dd($request);
$rules = [ $rules = [
'nama' => 'required|string', 'nama' => 'required|string',
'email' => 'required|email:rfc,dns', 'email' => 'required|email:rfc,dns',
...@@ -44,8 +46,6 @@ public function store(Request $request) { ...@@ -44,8 +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',
'konferensi' => 'required',
'kegiatan' => 'required',
'kode_registrasi' => 'required' 'kode_registrasi' => 'required'
]; ];
...@@ -63,25 +63,51 @@ public function store(Request $request) { ...@@ -63,25 +63,51 @@ public function store(Request $request) {
'alamat' => strip_tags($request->alamat), 'alamat' => strip_tags($request->alamat),
'kode_pos' => strip_tags($request->kodepos), 'kode_pos' => strip_tags($request->kodepos),
'kota' => strip_tags($request->kota), 'kota' => strip_tags($request->kota),
'id_konferensi' => $request->konferensi,
'id_kegiatan' => $request->kegiatan,
'kode_registrasi' => strip_tags($request->kode_registrasi) 'kode_registrasi' => strip_tags($request->kode_registrasi)
]; ];
$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); // $kegiatan = Kegiatan::find($request->kegiatan);
$konferensi = Konferensi::find($request->konferensi); // $konferensi = Konferensi::find($request->konferensi);
Registrasi::query()->create($registrasi);
$id_registrasi = Registrasi::query()->create($registrasi)->id;
foreach($request->konferensi as $kon){
$i = 0;
$daftarKonferensi[] = $kon;
$konferensi = Konferensi::select('nama')->where('id', $kon)->first();
foreach($request->input('kegiatan'.$i) as $keg){
$daftarKegiatan[] = $keg;
$kegiatan[] = Kegiatan::select('nama', 'harga')->where('id', $keg)->first();
}
$kegiatanpeserta[] = [
'id_registrasi' => $id_registrasi,
'id_kegiatan' => $kon,
'id_konferensi' => $daftarKonferensi[$i],
'nama_kegiatan' => $kegiatan[$i]['nama'],
'nama_konferensi' => $konferensi->nama,
'harga' => $kegiatan[$i]['harga']
];
$i++;
}
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', 'kegiatan', 'konferensi'))->with('success', 'Data saved successfully'); return view('invoice', compact('registrasi', 'tglRegistrasi', 'kegiatanpeserta'))->with('success', 'Data saved successfully');
} }
catch(Exception $e){ catch(Exception $e){
dd($e);
Log::error($e); Log::error($e);
DB::rollBack(); DB::rollBack();
......
...@@ -24,4 +24,8 @@ class Kegiatan extends Model ...@@ -24,4 +24,8 @@ class Kegiatan extends Model
public function rKegiatan() { public function rKegiatan() {
return $this->belongsToMany(Registrasi::class, 'id_kegiatan', 'id'); return $this->belongsToMany(Registrasi::class, 'id_kegiatan', 'id');
} }
public function pkKegiatanPeserta() {
return $this->hasMany(KegiatanPeserta::class, 'id_kegiatan', 'id');
}
} }
<?php
namespace App\Models;
use App\Traits\Uuid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class KegiatanPeserta extends Model
{
use HasFactory;
use Uuid;
public $incrementing = false;
protected $table = 'kegiatan_peserta';
protected $keyType = 'string';
protected $fillable = [
'id',
'id_registrasi',
'id_kegiatan',
'id_konferensi'
];
public function rRegistrasi() {
return $this->belongsTo(Registrasi::class, 'id_registrasi', 'id');
}
public function rKegiatanPeserta() {
return $this->belongsTo(Kegiatan::class, 'id_kegiatan', 'id');
}
public function rKonferensiPeserta() {
return $this->belongsTo(Konferensi::class, 'id_konferensi', 'id');
}
}
...@@ -23,4 +23,8 @@ class Konferensi extends Model ...@@ -23,4 +23,8 @@ class Konferensi extends Model
public function rKonferensi() { public function rKonferensi() {
return $this->belongsToMany(Registrasi::class, 'id_konferensi', 'id'); return $this->belongsToMany(Registrasi::class, 'id_konferensi', 'id');
} }
public function pkKonferensiPeserta() {
return $this->hasMany(Konferensi::class, 'id_konferensi', 'id');
}
} }
...@@ -38,4 +38,8 @@ public function pkKegiatan(){ ...@@ -38,4 +38,8 @@ public function pkKegiatan(){
public function pkKonferensi() { public function pkKonferensi() {
return $this->hasOne(Konferensi::class, 'id', 'id_konferensi'); return $this->hasOne(Konferensi::class, 'id', 'id_konferensi');
} }
public function pkRegistrasiPeserta() {
return $this->hasMany(KegiatanPeserta::class, 'id_registrasi', 'id');
}
} }
...@@ -72,17 +72,25 @@ ...@@ -72,17 +72,25 @@
@php @php
$no = 1; $no = 1;
$subtotal = 0; $subtotal = 0;
$i = 0;
@endphp
@foreach ($kegiatanpeserta as $keg)
@php
$subtotal = $subtotal + $keg['harga'];
@endphp @endphp
{{-- @foreach ($biaya as $tarif) --}}
<tr> <tr>
<td>1</td> <td>1</td>
<td> <td>
{{$kegiatan->nama}} <br> Konferensi : <b> {{$konferensi->nama}} </b> {{$keg['nama_kegiatan']}} <br> Konferensi : <b> {{$keg['nama_konferensi']}} </b>
</td> </td>
<td class="text-center">Rp {{$kegiatan->harga}}</td> <td class="text-center">Rp {{$keg['harga']}}</td>
<td class="text-center">1</td> <td class="text-center">1</td>
<td class="text-right">Rp {{$kegiatan->harga}}</td> <td class="text-right">Rp {{$keg['harga']}}</td>
</tr> </tr>
@php
$i++;
@endphp
@endforeach
</table> </table>
</div> </div>
<div class="row mt-4"> <div class="row mt-4">
...@@ -99,12 +107,12 @@ ...@@ -99,12 +107,12 @@
<div class="col-lg-4 text-right"> <div class="col-lg-4 text-right">
<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 {{$kegiatan->harga}}</div> <div class="invoice-detail-value">Rp {{$subtotal}}</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 {{$kegiatan->harga}}</div> <div class="invoice-detail-value invoice-detail-value-lg">Rp {{$subtotal}}</div>
</div> </div>
</div> </div>
</div> </div>
......
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