diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 72ce97fe..9b0e2f8f 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -40,6 +40,7 @@ use App\Models\Negeri; use Carbon\Carbon; use App\Models\LelongTebus; use App\Models\Tetapan; +use App\Models\TransaksiKeuntungan; class LelongController extends Controller @@ -119,20 +120,15 @@ class LelongController extends Controller $total14Kp = 0; $total14K = 0; $total9K = 0; - - $keuntungan = 0; - $total_upahkeuntungan = 0; - $total_upahkeuntungan2 = 0; $total_nilaimarhun = 0; $nilai_marhun = 0; - $totalkeuntungan = 0; - $totalkeuntungan2 = 0; + $total_bakiupah = 0; foreach($cawanganlel as $cawlel) { $cawangan = Cawangan::where('id','=',$cawlel->caw_id)->first(); - $databid = LelongBid::join('gadai','lelongbid.norujukan','=','gadai.norujukan') - ->select('lelongbid.bakiupah','lelongbid.id','lelongbid.berat','lelongbid.marhun','lelongbid.cajlelong','lelongbid.baki','lelongbid.nilaimarhun','lelongbid.pinjaman','lelongbid.hargaasas','lelongbid.cajlelong','gadai.bakipjm','gadai.bakihargajualan','gadai.upah12','gadai.ansakhir','gadai.tempoh','gadai.kadarupah','gadai.tempohbayar') + $databid = LelongBid::select('lelongbid.id','lelongbid.berat','lelongbid.marhun','lelongbid.cajlelong','lelongbid.baki','lelongbid.nilaimarhun', + 'lelongbid.pinjaman','lelongbid.hargaasas','lelongbid.cajlelong','lelongbid.bakiupah') ->where('caw_id','=',$cawlel->caw_id)->where('lelong_id','=',$id)->get(); // dd($databid->toArray()); @@ -140,12 +136,11 @@ class LelongController extends Controller $berat = 0; $pinjaman =0; $nilai_marhun = 0; - $upah = 0; + $bakiupah = 0; $hargaasas = 0; $cajlelong = 0; $rugilelong = 0; $bakilelong = 0; - $totalkeuntungan = 0; foreach($databid as $index1=>$bid) { @@ -153,17 +148,11 @@ class LelongController extends Controller $berat = $berat + $bid['berat']; $nilai_marhun = $nilai_marhun + $bid['nilaimarhun']; $pinjaman =$pinjaman + $bid['pinjaman']; - // $upah = $upah + $bid['upah']; + $bakiupah = $bakiupah + $bid['bakiupah']; $hargaasas = $hargaasas + $bid['hargaasas']; $cajlelong = $cajlelong + $bid['cajlelong']; - - $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); - $databid[$index1]['keuntungan'] = $keuntungan; - - $total_upahkeuntungan = bcdiv($total_upahkeuntungan,1,1) + bcdiv($keuntungan,1,1); - $totalkeuntungan = $totalkeuntungan + $bid['bakiupah']; - + if($bid['baki'] > 0) { $bakilelong = $bakilelong + $bid['baki']; @@ -229,29 +218,25 @@ class LelongController extends Controller 'berat'=>$berat, 'n_marhun'=>$nilai_marhun, 'pinjaman'=>$pinjaman, - 'upahsimpan'=>bcdiv($total_upahkeuntungan,1,1), - 'bakiupah'=>$totalkeuntungan, + 'upahsimpan'=>$bakiupah, + 'bakiupah'=>$bakiupah, 'hargaasas'=>$hargaasas, 'cajlelong'=>$cajlelong, 'rugilelong'=>$rugilelong, 'bakilelong'=>$bakilelong, ]); - $total_upahkeuntungan2 = $total_upahkeuntungan2 + $total_upahkeuntungan; $total_marhun = $total_marhun + sizeof($databid); $total_berat = $total_berat + $berat; $total_pinjaman = $total_pinjaman + $pinjaman; - $total_upah = $total_upah + 0; $total_hargaasas = $total_hargaasas + $hargaasas; $total_cazlelong = $total_cazlelong + $cajlelong; $total_rugilelong = $total_rugilelong + $rugilelong; $total_bakilelong = $total_bakilelong + $bakilelong; $total_nilaimarhun = $total_nilaimarhun + $nilai_marhun; + $total_bakiupah = $total_bakiupah + $bakiupah; - $totalkeuntungan2 = $totalkeuntungan2 + $totalkeuntungan; - - $data = Lelong::where('lelong.id','=',$lelong_id) ->get(); } @@ -283,11 +268,8 @@ class LelongController extends Controller 'lelong_id', 'jeniskarat', 'data', - 'keuntungan', - 'total_upahkeuntungan', - 'total_nilaimarhun', - 'total_upahkeuntungan2', - 'totalkeuntungan2')); + 'total_bakiupah', + 'total_nilaimarhun')); } public function create($id) @@ -436,7 +418,7 @@ class LelongController extends Controller } } - return redirect()->route('analisa.senaraisimulasi') + return redirect()->route('lelong.senarailelong') ->with('success','Create Lelong Berjaya'); } @@ -526,7 +508,9 @@ class LelongController extends Controller public function kemaskini(Request $request) { // dd($request->all()); - + $user = Auth::user(); + $currentdate = Carbon::now(); + $currentdate = $currentdate->toDateTimeString(); $lelkarat = lelKarat::where('lelong_id','=',$request->idlelong)->get(); foreach($lelkarat as $karat) //save old harga asas @@ -557,7 +541,13 @@ class LelongController extends Controller foreach($lelongbid as $index1=>$bid) { - $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); + //$keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); + $total_untung_rebet = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$bid['norujukan'])->sum('keuntungan_rebet'); + $total_untung_asal = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$bid['norujukan'])->sum('bayaran_keuntungan'); + $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + $keuntungan = bcdiv(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm'],1,1)-$beza_keuntungan; + // dd($keuntungan); + $sumhargaasas = 0; $lelongbidmarhun = LelongBidMarhun::where('lelongbid_id','=',$bid->id)->get(); foreach($lelongbidmarhun as $marhun) @@ -601,6 +591,16 @@ class LelongController extends Controller 'bakiupah'=> bcdiv($keuntungan,1,1), 'hargaasas'=> $sumhargaasas ]); + //insert loguser + $loguser = new LogUser; + $loguser->user_id = $user->id; + $loguser->date = $currentdate; + $loguser->username = $user->username; + $loguser->nama_user = $user->name; + $loguser->norujukan = $bid['norujukan']; + $loguser->nota = ' Kemaskini Harga Asas/Keuntungan '.bcdiv($keuntungan,1,1); + $loguser->save(); + } return redirect()->route('lelong.show',$request->idlelong) @@ -1005,14 +1005,21 @@ class LelongController extends Controller 'gadai.ansakhir', 'gadai.tempoh', 'gadai.tempohbayar', - 'gadai.kadarupah' + 'gadai.kadarupah', + 'gadai.nokp' ) ->get()->toArray(); foreach ($marhuns as $index1=> $cal) { - + + $customer = Customer::on('mysql2') + ->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); $marhuns[$index1]['keuntungan'] = bcdiv($keuntungan,1,1); + $marhuns[$index1]['nama'] = $customer; } $arrayinfo = []; @@ -1102,8 +1109,7 @@ class LelongController extends Controller $total9K = 0; $keuntungan = 0; - $total_upahkeuntungan = 0; - $total_upahkeuntungan2 = 0; + $total_bakiupah = 0; $total_nilaimarhun = 0; $nilai_marhun = 0; @@ -1112,8 +1118,11 @@ class LelongController extends Controller foreach($cawanganlel as $cawlel) { $cawangan = Cawangan::where('id','=',$cawlel->caw_id)->first(); - $databid = LelongBid::join('gadai','lelongbid.norujukan','=','gadai.norujukan') - ->select('lelongbid.t_lelong','lelongbid.bakiupah','lelongbid.hargaasas','lelongbid.id','lelongbid.berat','lelongbid.marhun','lelongbid.cajlelong','lelongbid.baki','lelongbid.nilaimarhun','lelongbid.pinjaman','lelongbid.hargaasas','lelongbid.cajlelong','gadai.bakipjm','gadai.bakihargajualan','gadai.upah12','gadai.ansakhir','gadai.tempoh','gadai.kadarupah','gadai.tempohbayar') + // $databid = LelongBid::join('gadai','lelongbid.norujukan','=','gadai.norujukan') + // ->select('lelongbid.t_lelong','lelongbid.bakiupah','lelongbid.hargaasas','lelongbid.id','lelongbid.berat','lelongbid.marhun','lelongbid.cajlelong','lelongbid.baki','lelongbid.nilaimarhun','lelongbid.pinjaman','lelongbid.hargaasas','lelongbid.cajlelong','gadai.bakipjm','gadai.bakihargajualan','gadai.upah12','gadai.ansakhir','gadai.tempoh','gadai.kadarupah','gadai.tempohbayar') + // ->where('caw_id','=',$cawlel->caw_id)->where('lelong_id','=',$id)->get(); + $databid = LelongBid::select('lelongbid.id','lelongbid.berat','lelongbid.marhun','lelongbid.cajlelong','lelongbid.baki','lelongbid.nilaimarhun', + 'lelongbid.pinjaman','lelongbid.hargaasas','lelongbid.cajlelong','lelongbid.bakiupah') ->where('caw_id','=',$cawlel->caw_id)->where('lelong_id','=',$id)->get(); // dd($databid->toArray()); @@ -1121,13 +1130,12 @@ class LelongController extends Controller $berat = 0; $pinjaman =0; $nilai_marhun = 0; - $upah = 0; + $bakiupah = 0; $hargaasas = 0; $cajlelong = 0; $rugilelong = 0; $bakilelong = 0; $cajlelong = 0; - $totalkeuntungan = 0; foreach($databid as $index1=>$bid) { @@ -1135,21 +1143,14 @@ class LelongController extends Controller $berat = $berat + $bid['berat']; $nilai_marhun = $nilai_marhun + $bid['nilaimarhun']; $pinjaman =$pinjaman + $bid['pinjaman']; - // $upah = $upah + $bid['upah']; + $bakiupah = $bakiupah + $bid['bakiupah']; $hargaasas = $hargaasas + $bid['hargaasas']; $cajlelong = $cajlelong + $bid['cajlelong']; - - $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); - $databid[$index1]['keuntungan'] = $keuntungan; - - $total_upahkeuntungan = bcdiv($total_upahkeuntungan,1,1) + bcdiv($keuntungan,1,1); - $totalkeuntungan = $totalkeuntungan + $bid['bakiupah']; - $lelongsim = Lelong::where('id',$id)->get(); $sumcajlelong = $bid['hargaasas'] * ($lelongsim[0]['cajlelong']/100); $cajlelong = $cajlelong + bcdiv($sumcajlelong,1,1); - $totalbaki = $bid['hargaasas'] - $bid['pinjaman'] - bcdiv($keuntungan,1,1) - bcdiv($sumcajlelong,1,1); + $totalbaki = $bid['hargaasas'] - $bid['pinjaman'] - $bid['bakiupah'] - bcdiv($sumcajlelong,1,1); if($totalbaki > 0) { @@ -1216,25 +1217,23 @@ class LelongController extends Controller 'berat'=>$berat, 'n_marhun'=>$nilai_marhun, 'pinjaman'=>$pinjaman, - 'upahsimpan'=>bcdiv($total_upahkeuntungan,1,1), - 'bakiupah'=>$totalkeuntungan, + 'upahsimpan'=>$bakiupah, + 'bakiupah'=>$bakiupah, 'hargaasas'=>$hargaasas, 'cajlelong'=>$cajlelong, 'rugilelong'=>$rugilelong, 'bakilelong'=>$bakilelong, ]); - $total_upahkeuntungan2 = $total_upahkeuntungan2 + $total_upahkeuntungan; $total_marhun = $total_marhun + sizeof($databid); $total_berat = $total_berat + $berat; $total_pinjaman = $total_pinjaman + $pinjaman; - $total_upah = $total_upah + 0; $total_hargaasas = $total_hargaasas + $hargaasas; $total_cazlelong = $total_cazlelong + $cajlelong; $total_rugilelong = $total_rugilelong + $rugilelong; $total_bakilelong = $total_bakilelong + $bakilelong; $total_nilaimarhun = $total_nilaimarhun + $nilai_marhun; - $totalkeuntungan2 = $totalkeuntungan2 + $totalkeuntungan; + $total_bakiupah = $total_bakiupah + $bakiupah; $data = Lelong::where('lelong.id','=',$lelong_id) @@ -1268,11 +1267,8 @@ class LelongController extends Controller 'lelong_id', 'jeniskarat', 'data', - 'keuntungan', - 'total_upahkeuntungan', - 'total_nilaimarhun', - 'total_upahkeuntungan2', - 'totalkeuntungan2')); + 'total_bakiupah', + 'total_nilaimarhun')); } public function senaraimarhunsimulasi($lelongid, $cawid){ @@ -1282,7 +1278,6 @@ class LelongController extends Controller $marhuns = LelongBid::join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id') - ->join('gadai','lelongbid.norujukan','=','gadai.norujukan') ->where('lelong_id','=',$lelongid)->where('caw_id','=',$cawid) ->select( 'lelongbid.t_lelong', @@ -1298,25 +1293,33 @@ class LelongController extends Controller 'lelongbid.baki', 'lelongbid.bakiupah', 'lelongbid.status_jual', - 'lelongbid.jbg', - 'gadai.bakipjm', - 'gadai.bakihargajualan', - 'gadai.upah12', - 'gadai.ansakhir', - 'gadai.tempoh', - 'gadai.tempohbayar', - 'gadai.kadarupah' + 'lelongbid.jbg' + ) ->get()->toArray(); foreach ($marhuns as $index1=> $cal) { + + // $customer = Customer::on('mysql2') + // ->where('kpbaru','=',$cal['nokp']) + // ->orWhere('kplama','=',$cal['nokp']) + // ->first(); + + // $total_untung_rebet = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$cal['norujukan'])->sum('keuntungan_rebet'); + // $total_untung_asal = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$cal['norujukan'])->sum('bayaran_keuntungan'); + // $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + // // dd($total_untung_rebet); - $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); - $marhuns[$index1]['keuntungan'] = bcdiv($keuntungan,1,1); + // // $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $beza_keuntungan)-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); + // $keuntungan = bcdiv(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm'],1,1)-$beza_keuntungan; + // // dd($keuntungan); + // $marhuns[$index1]['keuntungan'] = bcdiv($keuntungan,1,1); + // // dd(bcdiv($keuntungan,1,1)); + // $marhuns[$index1]['nama'] = $customer; $simulasilel = Lelong::where('id',$lelongid)->get(); $sumcajlelong = $cal['hargaasas'] * ($simulasilel[0]['cajlelong']/100); - $totalbaki = $cal['hargaasas'] - $cal['pinjaman'] - bcdiv($keuntungan,1,1) - bcdiv($sumcajlelong,1,1); + $totalbaki = $cal['hargaasas'] - $cal['pinjaman'] - $cal['bakiupah'] - bcdiv($sumcajlelong,1,1); $marhuns[$index1]['cajlelong'] = bcdiv($sumcajlelong,1,1); $marhuns[$index1]['baki'] = $totalbaki; @@ -1855,15 +1858,22 @@ class LelongController extends Controller foreach($senaraisagtempoh as $index1=>$datatempoh) { + //kemaskini keuntungan + $total_untung_rebet = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$datatempoh['norujukan'])->sum('keuntungan_rebet'); + $total_untung_asal = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$datatempoh['norujukan'])->sum('bayaran_keuntungan'); + $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + $keuntungan = bcdiv(($datatempoh['tempoh']-$datatempoh['tempohbayar'])*$datatempoh['kadarupah']/100*$datatempoh['bakipjm'],1,1)-$beza_keuntungan; + // dd($keuntungan); //kemaskini keuntungan baru - $keuntungan = $datatempoh['bakipjm'] - ($datatempoh['bakihargajualan'] - ($datatempoh['upah12'] - $datatempoh['ansakhir'])-(($datatempoh['tempoh']-$datatempoh['tempohbayar'])*$datatempoh['kadarupah']/100*$datatempoh['bakipjm']) ); - $senaraisagtempoh[$index1]['keuntungan'] = $keuntungan; + // $keuntungan = $datatempoh['bakipjm'] - ($datatempoh['bakihargajualan'] - ($datatempoh['upah12'] - $datatempoh['ansakhir'])-(($datatempoh['tempoh']-$datatempoh['tempohbayar'])*$datatempoh['kadarupah']/100*$datatempoh['bakipjm']) ); + // $senaraisagtempoh[$index1]['keuntungan'] = $keuntungan; // dd($data['norujukan']); $updatetempoh = LelongBid::where('norujukan', $datatempoh['norujukan']) ->where('lelong_id', $lelong_id) ->first(); $updatetempoh->jbg = $datatempoh['tempoh']; + $updatetempoh->pinjaman = $datatempoh['bakipjm']; $updatetempoh->bakiupah = bcdiv($keuntungan,1,1); $updatetempoh->update(); //insert loguser @@ -2539,9 +2549,10 @@ class LelongController extends Controller // dd($request->lelongidasal); $id = $request->lelongidasal; $idbaru = $request->lelongidbaru; + // dd($idbaru); $lelong = Lelong::where('id','=',$request->lelongidasal)->first(); - $cawanganlel = CawanganLelong::where('lelong_id','=',$id)->get(); - $lelkarat = Lelkarat::where('lelong_id','=',$id)->get(); + + // $simkarat = SimKarat::where('simulasi_id','=',$id)->get(); // dd($t_lelong); @@ -2555,6 +2566,7 @@ class LelongController extends Controller $lelong1->kali = $lelong->kali; $lelong1->save(); + $lelkarat = Lelkarat::where('lelong_id','=',$id)->get(); foreach($lelkarat as $lelongkarat) { $lelkarat = new LelKarat; @@ -2565,7 +2577,7 @@ class LelongController extends Controller $lelkarat->harga2 = $lelongkarat->harga2; $lelkarat->save(); } - + $cawanganlel = CawanganLelong::where('lelong_id','=',$id)->get(); foreach($cawanganlel as $caw) { $namacaw = CawanganLelong::join('cawangan','cawangan.id','=','cawangan_lelong.caw_id') @@ -2585,7 +2597,7 @@ class LelongController extends Controller } $caw_lelong = new CawanganLelong; $caw_lelong->batchlel = $batchno; - $caw_lelong->lelong_id = $idbaru; + $caw_lelong->lelong_id = $lelong1->id; $caw_lelong->caw_id = $caw->caw_id; $caw_lelong->online = $caw->online; $caw_lelong->lokasi = $caw->lokasi; @@ -2593,17 +2605,18 @@ class LelongController extends Controller $caw_lelong->kali = $caw->kali; $caw_lelong->save(); - $datalelbid = LelongBid::where('caw_id','=',$caw->caw_id)->where('lelong_id',$id)->get(); + $datalelbid = LelongBid::where('caw_id','=',$caw->caw_id)->where('lelong_id',$id)->where('status_jual','=', 0)->get(); $suratcaw = $datalelbid->all(); foreach(array_chunk($suratcaw,100) as $data_chunk) { - //dd($data); + // dd($datalelbid); foreach($data_chunk as $data) { //dd($simulasi->id); $caw_lelsag = LelongBid::where('norujukan', $data->norujukan) - ->where('status_jual','=', 0)->first(); - $caw_lelsag->lelong_id = $idbaru; + ->first(); + // dd($caw_lelsag); + $caw_lelsag->lelong_id = $lelong1->id; $caw_lelsag->update(); } @@ -2614,7 +2627,7 @@ class LelongController extends Controller $loguser->date = $currentdate; $loguser->username = $user->username; $loguser->nama_user = $user->name; - $loguser->nota = 'Daftar Batch Lelong '.$namacaw->caw_code.'-'.$id.' Kepada '.$idbaru; + $loguser->nota = 'Daftar Batch Lelong '.$namacaw->caw_code.'-'.$id.' Kepada '.$lelong1->id; $loguser->save(); } diff --git a/app/Http/Controllers/PembidaController.php b/app/Http/Controllers/PembidaController.php index 985c0610..cb5a4425 100644 --- a/app/Http/Controllers/PembidaController.php +++ b/app/Http/Controllers/PembidaController.php @@ -218,7 +218,7 @@ class PembidaController extends Controller $listwinner = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id') ->join('payment', 'lelongbidder.payment_id', '=', 'payment.id') ->where('lelongbidder.status_bidder', 1) - ->where('payment.status', 1) + // ->where('payment.status', 1) ->where('lelongbidder.status_payment', 1) ->where('lelongbid.lelong_id', $request->lelong_id) ->where('lelongbid.kodcaw', $request->kodcaw) @@ -241,7 +241,7 @@ class PembidaController extends Controller foreach($SAGWin as $index2=>$sag) { - + // dd($sag->payment_id); if($sag) { $detailspayment = Payment::where('id', $sag->payment_id)->first(); @@ -300,7 +300,7 @@ class PembidaController extends Controller $infos = LelongBid::join('cawangan', 'lelongbid.kodcaw', '=', 'cawangan.caw_code') ->join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id') ->where('lelongbidder.user_id', $user_id) - ->where('lelongbidder.payment_id', $payment_id) + // ->where('lelongbidder.payment_id', $payment_id) ->where('cawangan.caw_code', $kodcaw) ->where('lelongbid.kodcaw', $kodcaw) // ->where('lelongbidder.status_payment', 1) diff --git a/app/Http/Controllers/SimulasiController.php b/app/Http/Controllers/SimulasiController.php index 95ae9516..0649329e 100644 --- a/app/Http/Controllers/SimulasiController.php +++ b/app/Http/Controllers/SimulasiController.php @@ -29,6 +29,8 @@ use App\Models\LelKarat; use App\Models\LogUser; use App\Models\LelongTebus; use App\Models\Tetapan; +use App\Models\Customer; +use App\Models\TransaksiKeuntungan; @@ -69,15 +71,8 @@ class SimulasiController extends Controller // dd($fasa); // dd($fasa); //create simulasi - $simulasi = new Simulasi; - $simulasi->tarikh_lelong = $request->tarikh_lelong; - $simulasi->harga_emas_asas = $request->hargaasas; - $simulasi->jbg = $request->jbg; - $simulasi->cajlelong = $request->cajlelong; - $simulasi->fasa = $request->fasa; - $simulasi->kali = $request->kali; - $simulasi->save(); - $simulasi_id = $simulasi->id; + + // $simulasi_id = $simulasi->id; $jbgadai = ($t_lelong->subMonths($bulan))->toDateString(); if($request->fasa == '1'){ $surat = Gadai::where('t_gadai','<=',$jbgadai) @@ -106,7 +101,15 @@ class SimulasiController extends Controller { return redirect()->route('analisa.janasimulasi') ->with('failed','Tiada surat untuk di lelong'); - } + } + $simulasi = new Simulasi; + $simulasi->tarikh_lelong = $request->tarikh_lelong; + $simulasi->harga_emas_asas = $request->hargaasas; + $simulasi->jbg = $request->jbg; + $simulasi->cajlelong = $request->cajlelong; + $simulasi->fasa = $request->fasa; + $simulasi->kali = $request->kali; + $simulasi->save(); $cawangan = Cawangan::all(); @@ -155,6 +158,7 @@ class SimulasiController extends Controller // dd($data_chunk); foreach($data_chunk as $data) { + $simulasibid = SimulasiBid::create([ "simulasi_id" => $simulasi->id, "caw_id" => $cawsimulasi->id, @@ -302,16 +306,19 @@ class SimulasiController extends Controller $total14Kp = 0; $total14K = 0; $total9K = 0; - $total_upahkeuntungan2 = 0; + $total_bakiupah = 0; $total_nilaimarhun = 0; foreach($cawangansim as $cawsim) { $cawangan = Cawangan::where('id','=',$cawsim->caw_id)->first(); - $databid = SimulasiBid::join('gadai','simulasibid.norujukan','=','gadai.norujukan') - ->select('simulasibid.id','simulasibid.berat','simulasibid.marhun','simulasibid.cajlelong','simulasibid.baki','simulasibid.nilaimarhun', - 'simulasibid.pinjaman','simulasibid.hargaasas','simulasibid.cajlelong','gadai.bakipjm','gadai.bakihargajualan','gadai.upah12', - 'gadai.ansakhir','gadai.tempoh','gadai.kadarupah','gadai.tempohbayar') + // $databid = SimulasiBid::join('gadai','simulasibid.norujukan','=','gadai.norujukan') + // ->select('simulasibid.id','simulasibid.berat','simulasibid.marhun','simulasibid.cajlelong','simulasibid.baki','simulasibid.nilaimarhun', + // 'simulasibid.pinjaman','simulasibid.hargaasas','simulasibid.cajlelong','gadai.bakipjm','gadai.bakihargajualan','gadai.upah12', + // 'gadai.ansakhir','gadai.tempoh','gadai.kadarupah','gadai.tempohbayar') + // ->where('caw_id','=',$cawsim->caw_id)->where('simulasi_id','=',$simulasi_id)->get(); + $databid = SimulasiBid::select('simulasibid.id','simulasibid.berat','simulasibid.marhun','simulasibid.cajlelong','simulasibid.baki','simulasibid.nilaimarhun', + 'simulasibid.pinjaman','simulasibid.hargaasas','simulasibid.cajlelong','simulasibid.bakiupah') ->where('caw_id','=',$cawsim->caw_id)->where('simulasi_id','=',$simulasi_id)->get(); // ->toArray(); @@ -319,14 +326,14 @@ class SimulasiController extends Controller $berat = 0; $nilai_marhun = 0; $pinjaman =0; - $upah = 0; + $bakiupah = 0; $hargaasas = 0; $cajlelong = 0; $rugilelong = 0; $bakilelong = 0; - $keuntungan = 0; - $total_upahkeuntungan = 0; + // $keuntungan = 0; + // $total_upahkeuntungan = 0; foreach($databid as $index1=>$bid) @@ -336,16 +343,16 @@ class SimulasiController extends Controller // $nilai_marhun = $nilai_marhun + ($marhun->sum('n_marhun')); $nilai_marhun = $nilai_marhun + $bid['nilaimarhun']; $pinjaman =$pinjaman + $bid['pinjaman']; - // $upah = $upah + $bid['upah']; + $bakiupah = $bakiupah + $bid['bakiupah']; $hargaasas = $hargaasas + $bid['hargaasas']; $cajlelong = $cajlelong + $bid['cajlelong']; - $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); - $databid[$index1]['keuntungan'] = $keuntungan; + // $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); + // $databid[$index1]['keuntungan'] = $keuntungan; - // $total_upahkeuntungan = $total_upahkeuntungan + $keuntungan; - $total_upahkeuntungan = bcdiv($total_upahkeuntungan,1,1) + bcdiv($keuntungan,1,1); + // // $total_upahkeuntungan = $total_upahkeuntungan + $keuntungan; + // $total_upahkeuntungan = bcdiv($total_upahkeuntungan,1,1) + bcdiv($keuntungan,1,1); @@ -415,7 +422,8 @@ class SimulasiController extends Controller 'berat'=>$berat, 'n_marhun'=>$nilai_marhun, 'pinjaman'=>$pinjaman, - 'upahsimpan'=>bcdiv($total_upahkeuntungan,1,1), + 'upahsimpan'=>$bakiupah, + 'bakiupah'=>$bakiupah, 'hargaasas'=>$hargaasas, 'cajlelong'=>$cajlelong, 'rugilelong'=>$rugilelong, @@ -426,13 +434,12 @@ class SimulasiController extends Controller $total_marhun = $total_marhun + sizeof($databid); $total_berat = $total_berat + $berat; $total_nilaimarhun = $total_nilaimarhun + $nilai_marhun; - //dd($nilai_marhun); $total_pinjaman = $total_pinjaman + $pinjaman; $total_hargaasas = $total_hargaasas + $hargaasas; $total_cazlelong = $total_cazlelong + $cajlelong; $total_rugilelong = $total_rugilelong + $rugilelong; $total_bakilelong = $total_bakilelong + $bakilelong; - $total_upahkeuntungan2 = $total_upahkeuntungan2 + $total_upahkeuntungan; + $total_bakiupah = $total_bakiupah + $bakiupah; $data = Simulasi::where('simulasi.id','=',$simulasi_id) @@ -468,9 +475,8 @@ class SimulasiController extends Controller 'simulasi_id', 'jeniskarat', 'data', - 'total_upahkeuntungan', - 'total_nilaimarhun', - 'total_upahkeuntungan2' + 'total_bakiupah', + 'total_nilaimarhun' )); } @@ -502,6 +508,9 @@ class SimulasiController extends Controller public function kemaskini(Request $request) { // dd($request->idsimulasi); + $user = Auth::user(); + $currentdate = Carbon::now(); + $currentdate = $currentdate->toDateTimeString(); $simkarat = SimKarat::where('simulasi_id','=',$request->idsimulasi)->get(); foreach($simkarat as $karat) //save old harga asas @@ -531,7 +540,13 @@ class SimulasiController extends Controller //dd($simulasibid); foreach($simulasibid as $bid) { - $keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); + //$keuntungan = $bid['bakipjm'] - ($bid['bakihargajualan'] - ($bid['upah12'] - $bid['ansakhir'])-(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm']) ); + $total_untung_rebet = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$bid['norujukan'])->sum('keuntungan_rebet'); + $total_untung_asal = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$bid['norujukan'])->sum('bayaran_keuntungan'); + $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + $keuntungan = bcdiv(($bid['tempoh']-$bid['tempohbayar'])*$bid['kadarupah']/100*$bid['bakipjm'],1,1)-$beza_keuntungan; + // dd($keuntungan); + $sumhargaasas = 0; $simulasibidmarhun = SimulasiBidMarhun::where('simulasibid_id','=',$bid['id'])->get(); // dd($simulasibidmarhun); @@ -580,6 +595,16 @@ class SimulasiController extends Controller 'cajlelong'=> bcdiv($sumcajlelong,1,1), 'baki'=> $totalbaki, ]); + + //insert loguser + $loguser = new LogUser; + $loguser->user_id = $user->id; + $loguser->date = $currentdate; + $loguser->username = $user->username; + $loguser->nama_user = $user->name; + $loguser->norujukan = $bid['norujukan']; + $loguser->nota = ' Kemaskini Harga Asas/Keuntungan '.bcdiv($keuntungan,1,1); + $loguser->save(); //dd($sumcajlelong); @@ -835,16 +860,21 @@ class SimulasiController extends Controller 'gadai.ansakhir', 'gadai.tempoh', 'gadai.tempohbayar', - 'gadai.kadarupah' + 'gadai.kadarupah', + 'gadai.nokp' ) ->get()->toArray(); foreach($marhuns as $index1=>$cal){ - + $customer = Customer::on('mysql2') + ->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); - $marhuns[$index1]['keuntungan'] = $keuntungan; + $marhuns[$index1]['keuntungan'] = $keuntungan; + $marhuns[$index1]['nama'] = $customer; } @@ -1125,7 +1155,7 @@ class SimulasiController extends Controller $lelongtebus->teller = $user->name; $lelongtebus->norujukan = $data['norujukan']; $lelongtebus->batch_no = $simulasi_id; - $lelongtebus->nilai_marhun = $data['nilaimarhun']; + $lelongtebus->nilaimarhun = $data['nilaimarhun']; $lelongtebus->pinjaman = $data['pinjaman']; $lelongtebus->upah = $data['bakiupah']; $lelongtebus->jbg = $data['jbg']; @@ -1155,18 +1185,27 @@ class SimulasiController extends Controller $query->select('norujukan') ->from('gadai'); }) - ->select('gadai.norujukan','gadai.tempoh') + ->select('gadai.tempoh','gadai.tempohbayar','gadai.kadarupah','gadai.norujukan','gadai.tempoh','gadai.bakipjm') ->get()->toArray(); // dd($senaraisagtempoh); foreach($senaraisagtempoh as $datatempoh) { - // dd($data['norujukan']); + //kemaskini keuntungan + $total_untung_rebet = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$datatempoh['norujukan'])->sum('keuntungan_rebet'); + $total_untung_asal = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$datatempoh['norujukan'])->sum('bayaran_keuntungan'); + $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + $keuntungan = bcdiv(($datatempoh['tempoh']-$datatempoh['tempohbayar'])*$datatempoh['kadarupah']/100*$datatempoh['bakipjm'],1,1)-$beza_keuntungan; + // dd($keuntungan); + //update dalam simulasibid $updatetempoh = SimulasiBid::where('norujukan', $datatempoh['norujukan']) ->where('simulasi_id', $simulasi_id) ->first(); $updatetempoh->jbg = $datatempoh['tempoh']; + $updatetempoh->pinjaman = $datatempoh['bakipjm']; + $updatetempoh->bakiupah = bcdiv($keuntungan,1,1); $updatetempoh->update(); + //insert loguser $loguser = new LogUser; $loguser->user_id = $user->id; @@ -1174,7 +1213,7 @@ class SimulasiController extends Controller $loguser->username = $user->username; $loguser->nama_user = $user->name; $loguser->norujukan = $datatempoh['norujukan']; - $loguser->nota = ' Kemaskini Tempoh '.$simulasi_id; + $loguser->nota = $simulasi_id.' Kemaskini Tempoh/Bakipjm/Keuntungan' ; $loguser->save(); } @@ -1188,5 +1227,39 @@ class SimulasiController extends Controller return redirect()->route('analisa.senaraisimulasi') ->with('success','Kemaskini Berjaya'); } + + public function listsagbycust($simulasi_id, $cawid) + { + $keuntungan = 0; + + $marhuns = SimulasiBid::join('cawangan', 'simulasibid.caw_id', '=', 'cawangan.id') + ->join('gadai','simulasibid.norujukan','=','gadai.norujukan') + ->where('simulasi_id','=',$simulasi_id) + ->where('caw_id','=',$cawid) + ->groupBy('gadai.nokp') + ->select('gadai.nokp') + ->get()->toArray(); + // dd($marhuns); + + foreach($marhuns as $index1=>$cal){ + $customer = Customer::on('mysql2') + ->where('kpbaru','=',$cal['nokp']) + ->orWhere('kplama','=',$cal['nokp']) + ->first(); + + $listsag = SimulasiBid::join('gadai', 'gadai.norujukan','=','simulasibid.norujukan') + ->where('gadai.nokp','=',$cal['nokp']) + ->get(); + // dd($listsag); + + // $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); + // $marhuns[$index1]['keuntungan'] = $keuntungan; + $marhuns[$index1]['nama'] = $customer; + $marhuns[$index1]['listsag'] = $listsag; + + + } + return view('simulasi.listsagbycust',compact('marhuns','simulasi_id','cawid','listsag')); + } } \ No newline at end of file diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 06013a88..443204a7 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model; class Customer extends Model { use HasFactory; - + protected $connection = 'mysql2'; protected $table = 'customer'; protected $fillable = [ diff --git a/app/Models/TransaksiKeuntungan.php b/app/Models/TransaksiKeuntungan.php new file mode 100644 index 00000000..b036f805 --- /dev/null +++ b/app/Models/TransaksiKeuntungan.php @@ -0,0 +1,28 @@ + [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), - 'host' => '127.0.0.1', - 'port' => '3306', - 'database' => 'name', - 'username' => 'username', - 'password' => "password", + 'host' => env('DB_HOST_2', '127.0.0.1'), + 'port' => env('DB_PORT_2', '3306'), + 'database' => env('DB_DATABASE_2', 'forge'), + 'username' => env('DB_USERNAME_2', 'forge'), + 'password' => env('DB_PASSWORD_2', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', @@ -92,6 +92,9 @@ return [ ]) : [], ], + + + 'pgsql' => [ 'driver' => 'pgsql', 'url' => env('DATABASE_URL'), diff --git a/resources/views/lelong/senaraimarhun.blade.php b/resources/views/lelong/senaraimarhun.blade.php index 4b6d6287..3a92f283 100644 --- a/resources/views/lelong/senaraimarhun.blade.php +++ b/resources/views/lelong/senaraimarhun.blade.php @@ -48,6 +48,7 @@
{{ $message }}
+{{ $message }}
@endif +