diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index 2871b28c..72a54180 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -198,6 +198,7 @@ class LelongMobileController extends Controller $lelongBidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id') ->where('user_id', $userId) ->where('caw_id', $cawangan) + ->where('lelong_id', $request->lelongId) ->get()->toArray(); $total_hargabida = 0; @@ -208,7 +209,7 @@ class LelongMobileController extends Controller $marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray(); $lelongBidder[$index1]['lelongbidmarhun'] = $marhun; } - $groupCawangan[$index]['total_berat'] = $total_berat; + $groupCawangan[$index]['total_berat'] = number_format((float)$total_berat, 2, '.', ''); $groupCawangan[$index]['total_bidaan'] = number_format((float)$total_hargabida, 2, '.', ''); $groupCawangan[$index]['lelongbid'] = $lelongBidder; } diff --git a/app/Http/Controllers/SimulasiController.php b/app/Http/Controllers/SimulasiController.php index 16b29c82..ea3d6215 100644 --- a/app/Http/Controllers/SimulasiController.php +++ b/app/Http/Controllers/SimulasiController.php @@ -943,14 +943,21 @@ class SimulasiController extends Controller public function show($id) { $simulasi_id = $id; - $simulasi = Simulasi::where('id', '=', $id)->first(); + $simulasi = Simulasi::with(['cawangan', 'simulasiBid.simulasiBidMarhun'])->where('id', '=', $id)->first(); $data = $simulasi; $simkarat = SimKarat::where('simulasi_id', '=', $id)->get(); $jeniskarat = JenisKarat::all(); - $cawangansim = CawanganSimulasi::with(['cawangan', 'simulasiBid.simulasiBidMarhun'])->where('simulasi_id', '=', $id)->get(); - // $simulasiBidByCawangan = SimulasiBid::with(['simulasiBidMarhun'])->where('simulasi_id', '=', $id)->get()->groupBy('cawangan.caw_name'); - // $totalSimBid = collect($simulasiBidByCawangan)->groupBy('cawangan.caw_name')->flatten(2)->pluck('id'); - // $simulasiBidMarhun = SimulasiBidMarhun::whereIn('simulasibid_id',$totalSimBid)->get(); + + $cawanganAll = $simulasi->cawangan; + $simBidGroupByCawId = $simulasi->simulasiBid->groupBy('caw_id'); + + foreach($cawanganAll as $caw_key_by_id) + { + if($simBidGroupByCawId[$caw_key_by_id['id']]); + { + $caw_key_by_id['simulasiBid'] = $simBidGroupByCawId[$caw_key_by_id['id']]; + } + } $total24Kgb = 0; $total24K = 0; @@ -974,85 +981,7 @@ class SimulasiController extends Controller $total_hargaasas = 0; $arraycaw = []; - // foreach($simulasiBidByCawangan as $index => $cawangan) { - // $berat = 0; - // $nilai_marhun = 0; - // $pinjaman = 0; - // $bakiupah = 0; - // $hargaasas = 0; - // $cajlelong = 0; - // $bakilelong = 0; - // $rugilelong = 0; - - // $berat = $cawangan->sum('berat'); - // $nilai_marhun = $cawangan->sum('nilaimarhun'); - // $pinjaman = $cawangan->sum('pinjaman'); - // $bakiupah = $cawangan->sum('bakiupah'); - // $hargaasas = $cawangan->sum('hargaasas'); - // $cajlelong = $cawangan->sum('cajlel$cajlelong'); - - // $pluckBaki = $cawangan->pluck('baki'); - // $counted = $pluckBaki->countBy(function ($baki) use (&$bakilelong, &$rugilelong) { - // if ($baki > 0) { - // $bakilelong += $baki; - // } else { - // $rugilelong -= $baki; - // } - // }); - - // array_push($arraycaw, [ - // 'id_cawangan' => $cawangan[0]->caw_id, - // 'cawangan' => $index, - // 't_lelong' => $simulasi['tarikh_lelong'], - // 'bil_marhun' => sizeof($cawangan->toArray()), - // 'berat' => $berat, - // 'n_marhun' => $nilai_marhun, - // 'pinjaman' => $pinjaman, - // 'upahsimpan' => $bakiupah, - // 'bakiupah' => $bakiupah, - // 'hargaasas' => $hargaasas, - // 'cajlelong' => $cajlelong, - // 'rugilelong' => $rugilelong, - // 'bakilelong' => $bakilelong, - // ]); - - // $total_nilaimarhun += $nilai_marhun; - // $total_pinjaman += $pinjaman; - // $total_bakiupah += $bakiupah; - // $total_rugilelong += $rugilelong; - // $total_bakilelong += $bakilelong; - // $total_cazlelong += $cajlelong; - // $total_berat += $berat; - // $total_hargaasas += $hargaasas; - - // } - - // foreach ($simulasiBidMarhun as $sim_bid_marhun) { - // if ($sim_bid_marhun->karat == "24.0Kgb") { - // $total24Kgb += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "24.0K") { - // $total24K += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "23.0K") { - // $total23k += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "22.0K") { - // $total22K += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "21.0K") { - // $total21K += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "20.0Kp") { - // $total20K += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "18.0Kp") { - // $total18Kp += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "18.0K") { - // $total18K += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "14.0Kp") { - // $total14Kp += $sim_bid_marhun->berat; - // } else if ($sim_bid_marhun->karat == "14.0K") { - // $total14K += $sim_bid_marhun->berat; - // } - // } - - - foreach ($cawangansim as $caw) { + foreach ($cawanganAll as $caw) { $berat = 0; $nilai_marhun = 0; $pinjaman = 0; @@ -1061,7 +990,7 @@ class SimulasiController extends Controller $cajlelong = 0; $rugilelong = 0; $bakilelong = 0; - foreach ($caw->simulasiBid_id() as $sim_bid) { + foreach ($caw['simulasiBid'] as $sim_bid) { $total_marhun += 1; $nilai_marhun += $sim_bid->nilaimarhun; $pinjaman += $sim_bid->pinjaman; @@ -1070,11 +999,9 @@ class SimulasiController extends Controller $hargaasas += $sim_bid->hargaasas; $cajlelong += $sim_bid->cajlelong; - $lelongcaj = Simulasi::where('id',$id)->get(); - $sumcajlelong = $sim_bid['hargaasas'] * ($lelongcaj[0]['cajlelong']/100); + $sumcajlelong = $sim_bid['hargaasas'] * ($simulasi['cajlelong']/100); $cajlelong = $cajlelong + bcdiv($sumcajlelong,1,1); $totalbaki = $sim_bid['hargaasas'] - $sim_bid['pinjaman'] - $sim_bid['bakiupah'] - bcdiv($sumcajlelong,1,1); - if(strpos($totalbaki, '-') !== false) { $rugi = -$totalbaki; @@ -1096,7 +1023,7 @@ class SimulasiController extends Controller $total22K += $sim_bid_marhun->berat; } else if ($sim_bid_marhun->karat == "21.0K") { $total21K += $sim_bid_marhun->berat; - } else if ($sim_bid_marhun->karat == "20.0Kp") { + } else if ($sim_bid_marhun->karat == "20.0K") { $total20K += $sim_bid_marhun->berat; } else if ($sim_bid_marhun->karat == "18.0Kp") { $total18Kp += $sim_bid_marhun->berat; @@ -1109,11 +1036,12 @@ class SimulasiController extends Controller } } } + array_push($arraycaw, [ - 'id_cawangan' => $caw['caw_id'], - 'cawangan' => $caw->cawangan->caw_name, + 'id_cawangan' => $caw['id'], + 'cawangan' => $caw->caw_name, 't_lelong' => $simulasi['tarikh_lelong'], - 'bil_marhun' => sizeof($caw->simulasiBid_id()), + 'bil_marhun' => count($caw['simulasiBid']), 'berat' => $berat, 'n_marhun' => $nilai_marhun, 'pinjaman' => $pinjaman, diff --git a/app/Models/Cawangan.php b/app/Models/Cawangan.php index 8f5b1035..3ebb860a 100644 --- a/app/Models/Cawangan.php +++ b/app/Models/Cawangan.php @@ -30,13 +30,35 @@ class Cawangan extends Model 'para2', 'para3', ]; - public function lelongBid() + + public function simulasi() { - return $this->hasMany(LelongBid::class, 'caw_id', 'caw_id'); + return $this->belongsToMany(Simulasi::class, 'cawangan_simulasi', 'caw_id', 'simulasi_id'); } - public function cawangan() + public function lelong() { - return $this->hasOne(Cawangan::class, 'id'); + return $this->belongsToMany(Lelong::class, 'cawangan_lelong', 'caw_id', 'lelong_id'); } + + public function cawanganSimulasi() + { + return $this->hasMany(CawanganSimulasi::class, 'caw_id', 'id'); + } + + public function cawanganLelong() + { + return $this->hasMany(CawanganLelong::class, 'caw_id', 'id'); + } + + public function simulasiBid() + { + return $this->hasMany(SimulasiBid::class, 'caw_id', 'id'); + } + + public function lelongBid() + { + return $this->hasMany(LelongBid::class, 'caw_id', 'id'); + } + } diff --git a/app/Models/CawanganLelong.php b/app/Models/CawanganLelong.php index 627fa868..51ec8493 100644 --- a/app/Models/CawanganLelong.php +++ b/app/Models/CawanganLelong.php @@ -32,8 +32,12 @@ class CawanganLelong extends Model } public function cawangan() - { - return $this->hasOne(Cawangan::class, 'id', 'caw_id'); + return $this->belongsTo(Cawangan::class, 'caw_id', 'id'); + } + + public function lelong() + { + return $this->belongsTo(Lelong::class, 'lelong_id', 'id'); } } diff --git a/app/Models/CawanganSimulasi.php b/app/Models/CawanganSimulasi.php index c507fd68..c81265de 100644 --- a/app/Models/CawanganSimulasi.php +++ b/app/Models/CawanganSimulasi.php @@ -22,20 +22,15 @@ class CawanganSimulasi extends Model 'lokasi' ]; + // function below to delete public function gadaiTemp() { return $this->hasMany(GadaiTemp::class, 'kodcaw', 'norujukan'); } public function cawangan() - { - return $this->hasOne(Cawangan::class, 'id', 'caw_id'); - } - - public function simulasiBid() - { - return $this->hasMany(SimulasiBid::class, 'caw_id', 'caw_id'); + return $this->belongsTo(Cawangan::class, 'caw_id', 'id'); } public function simulasiBid_id() diff --git a/app/Models/Lelong.php b/app/Models/Lelong.php index 2433b8e2..d3bee12d 100644 --- a/app/Models/Lelong.php +++ b/app/Models/Lelong.php @@ -21,8 +21,18 @@ class Lelong extends Model 'sts_lelong' ]; + public function cawangan() + { + return $this->belongsToMany(Cawangan::class, 'cawangan_lelong', 'lelong_id', 'caw_id'); + } + public function cawanganLelong() { return $this->hasMany(CawanganLelong::class, 'lelong_id'); } + + public function lelongBid() + { + return $this->hasMany(LelongBid::class, 'lelong_id', 'id'); + } } diff --git a/app/Models/LelongBid.php b/app/Models/LelongBid.php index 5a0f5b2f..ffc71a37 100644 --- a/app/Models/LelongBid.php +++ b/app/Models/LelongBid.php @@ -40,6 +40,11 @@ class LelongBid extends Model 'fasa' ]; + public function cawangan() + { + return $this->belongsTo(Cawangan::class, 'caw_id','id'); + } + public function lelongbidder() { return $this->hasOne(LelongBidder::class,'lelongbid_id', 'id' ); } @@ -52,13 +57,13 @@ class LelongBid extends Model return $this->hasOne(FileMarhun::class, 'lelongbidmarhun_id'); } + public function lelong() + { + return $this->belongsTo(Lelong::class, 'lelong_id', 'id'); + } + public function lelongBidMarhun() { return $this->hasMany(LelongBidMarhun::class, 'lelongbid_id', 'id'); } - - public function statusLelongBidMarhun() - { - return $this->hasMany(LelongBidMarhun::class, 'lelongbid_id', 'id')->take(1); - } } diff --git a/app/Models/SimKarat.php b/app/Models/SimKarat.php index e03beb1d..bcdb4bbc 100644 --- a/app/Models/SimKarat.php +++ b/app/Models/SimKarat.php @@ -19,4 +19,9 @@ class SimKarat extends Model 'harga2', 'simulasi_id' ]; + + public function simulasi() + { + return $this->belongsTo(Simulasi::class, 'simulasi_id', 'id'); + } } diff --git a/app/Models/SimKarat_temp.php b/app/Models/SimKarat_temp.php index 150f3e54..91e7ffc5 100644 --- a/app/Models/SimKarat_temp.php +++ b/app/Models/SimKarat_temp.php @@ -17,6 +17,12 @@ class SimKarat_temp extends Model 'keterangan', 'harga', 'harga2', - 't_harga' + 't_harga', + 'simulasi_id' ]; + + public function simulasi() + { + return $this->belongsTo(Simulasi::class, 'simulasi_id', 'id'); + } } diff --git a/app/Models/Simulasi.php b/app/Models/Simulasi.php index dd12d52f..f8d20b2b 100644 --- a/app/Models/Simulasi.php +++ b/app/Models/Simulasi.php @@ -22,8 +22,34 @@ class Simulasi extends Model 'success_import', ]; - public function statusSimulasiBid() + public function cawangan() { - return $this->hasMany(SimulasiBid::class, 'simulasi_id', 'id')->take(1); + return $this->belongsToMany(Cawangan::class, 'cawangan_simulasi', 'simulasi_id', 'caw_id')->withPivot('id', 'export_data_stsdate', 'fasa'); + } + + // TBD - NOT RECOMMENDED FUNCTION BELOW + public function cawanganFromSimulasiBid() + { + return $this->belongsToMany(Cawangan::class, 'simulasibid', 'simulasi_id', 'caw_id'); + } + + public function cawanganSimulasi() + { + return $this->hasMany(CawanganSimulasi::class, 'simulasi_id', 'id'); + } + + public function simulasiBid() + { + return $this->hasMany(SimulasiBid::class, 'simulasi_id', 'id'); + } + + public function simkarat() + { + return $this->hasMany(SimKarat::class, 'simulasi_id', 'id'); + } + + public function simkarat_temp() + { + return $this->hasMany(SimKarat_temp::class, 'simulasi_id', 'id'); } } diff --git a/app/Models/SimulasiBid.php b/app/Models/SimulasiBid.php index 659825f7..f3d0779e 100644 --- a/app/Models/SimulasiBid.php +++ b/app/Models/SimulasiBid.php @@ -40,18 +40,18 @@ class SimulasiBid extends Model 'fasa', ]; + public function cawangan() + { + return $this->belongsTo(Cawangan::class, 'caw_id', 'id'); + } + + public function simulasi() + { + return $this->belongsTo(Simulasi::class, 'simulasi_id', 'id'); + } + public function simulasiBidMarhun() { return $this->hasMany(SimulasiBidMarhun::class, 'simulasibid_id', 'id'); } - - public function statusSimulasiBidMarhun() - { - return $this->hasMany(SimulasiBidMarhun::class, 'simulasibid_id', 'id')->take(1); - } - - public function cawangan() - { - return $this->hasOne(Cawangan::class, 'id', 'caw_id'); - } }