diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 9b0e2f8f..3b7a31fc 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -999,6 +999,7 @@ class LelongController extends Controller 'lelongbid.bakiupah', 'lelongbid.status_jual', 'lelongbid.jbg', + 'gadai.pinjaman as pinjasal', 'gadai.bakipjm', 'gadai.bakihargajualan', 'gadai.upah12', @@ -1006,9 +1007,11 @@ class LelongController extends Controller 'gadai.tempoh', 'gadai.tempohbayar', 'gadai.kadarupah', - 'gadai.nokp' + 'gadai.nokp', + 'gadai.bakiupah as upah6bulan' ) ->get()->toArray(); + // dd($marhuns); foreach ($marhuns as $index1=> $cal) { @@ -1017,6 +1020,10 @@ class LelongController extends Controller ->orWhere('kplama','=',$cal['nokp']) ->first(); + $ktlhbyr = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$cal['norujukan'])->sum('bayaran_keuntungan'); + // dd($ktlhbyr); + $marhuns[$index1]['ktlhbyr'] = $ktlhbyr; + $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; @@ -2635,6 +2642,49 @@ class LelongController extends Controller ->with('success','Create Lelong Berjaya'); } + public function listsagbycust($lelongid, $cawid) + { + $keuntungan = 0; + + $marhuns = LelongBid::join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id') + ->join('gadai','lelongbid.norujukan','=','gadai.norujukan') + ->where('lelong_id','=',$lelongid) + ->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 = LelongBid::join('gadai', 'gadai.norujukan','=','lelongbid.norujukan') + ->where('gadai.nokp','=',$cal['nokp']) + ->select('lelongbid.bakiupah', 'gadai.bakiupah as 6bulan','lelongbid.norujukan','lelongbid.nilaimarhun','lelongbid.berat','lelongbid.hargaasas','lelongbid.pinjaman','gadai.pinjaman as pinjasal','gadai.tempoh' ) + ->get(); + // dd($listsag); + foreach($listsag as $index=>$listing){ + $ktlhbyr = TransaksiKeuntungan::on('mysql2')->where('norujukan','=',$listing['norujukan'])->sum('bayaran_keuntungan'); + // dd($ktlhbyr); + $listsag[$index]['ktlhbyr'] = $ktlhbyr; + } + + + + // $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; + // $marhuns[$index1]['ktlhbyr'] = $ktlhbyr; + // dd($total_untung_asal); + + + } + return view('lelong.listsagbycust',compact('marhuns','lelongid','cawid','listsag','ktlhbyr')); + } diff --git a/app/Http/Controllers/SimulasiController.php b/app/Http/Controllers/SimulasiController.php index c2082164..81b9fbb4 100644 --- a/app/Http/Controllers/SimulasiController.php +++ b/app/Http/Controllers/SimulasiController.php @@ -111,7 +111,7 @@ class SimulasiController extends Controller //create simulasi $simulasi = Simulasi::create([ - 'tarikh_lelong' => $t_lelong, + 'tarikh_lelong' => $request->tarikh_lelong, 'harga_emas_asas' => $hargaasas, 'jbg' => $jbg, 'cajlelong' => $request->cajlelong, @@ -801,7 +801,7 @@ class SimulasiController extends Controller $keuntungan = 0; $marhuns = SimulasiBid::join('cawangan', 'simulasibid.caw_id', '=', 'cawangan.id') - ->join('gadai','simulasibid.norujukan','=','gadai.norujukan') + // ->join('gadai','simulasibid.norujukan','=','gadai.norujukan') ->where('simulasi_id','=',$simulasi_id) ->where('caw_id','=',$cawid) ->select( @@ -817,34 +817,51 @@ class SimulasiController extends Controller 'simulasibid.cajlelong', 'simulasibid.baki', 'simulasibid.status_jual', - 'simulasibid.jbg', - 'gadai.bakipjm', - 'gadai.bakihargajualan', - 'gadai.upah12', - 'gadai.ansakhir', - 'gadai.tempoh', - 'gadai.tempohbayar', - 'gadai.kadarupah', - 'gadai.nokp' + 'simulasibid.jbg' + // 'gadai.bakipjm', + // 'gadai.bakihargajualan', + // 'gadai.upah12', + // 'gadai.ansakhir', + // 'gadai.tempoh', + // 'gadai.tempohbayar', + // 'gadai.kadarupah', + // 'gadai.nokp' ) ->get()->toArray(); - + // dd($marhuns); + $arraymarhun = []; foreach($marhuns as $index1=>$cal){ - $customer = Customer::on('mysql2') - ->where('kpbaru','=',$cal['nokp']) - ->orWhere('kplama','=',$cal['nokp']) - ->first(); + // dd($cal); + $gadai = Gadai::on($cal['kodcaw']) + ->where('norujukan','=',$cal['norujukan']) + ->first(); + // dd($gadai); + $customer = Customer::where('kpbaru','=',$gadai['nokp']) + ->orWhere('kplama','=',$gadai['nokp']) + ->first(); + // dd($customer); - $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); + // $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; - + array_push($arraymarhun,[ + 'norujukan' => $cal['norujukan'], + 'tempoh' => $gadai['tempoh'], + 'nama' => $customer['nama'], + 'berat' => $cal['berat'], + 'nilaimarhun' => $cal['nilaimarhun'], + 'hargaasas' => $cal['hargaasas'], + 'pinjaman' => $cal['pinjaman'], + 'bakiupah' => $cal['bakiupah'], + 'cajlelong' => $cal['cajlelong'], + 'baki' => $cal['baki'], + ]); } - return view('simulasi.senaraimarhunlel',compact('marhuns','simulasi_id','cawid','keuntungan')); + return view('simulasi.senaraimarhunlel',compact('arraymarhun','marhuns','simulasi_id','cawid','keuntungan')); } public function deletemarhunlel(Request $request){ @@ -1054,118 +1071,151 @@ class SimulasiController extends Controller $currentdate = Carbon::now(); $currentdate = $currentdate->toDateTimeString(); $data = []; - $senaraisag = SimulasiBid::where('simulasibid.simulasi_id', $simulasi_id) - ->whereNotIn('simulasibid.norujukan', function($query) { - $query->select('norujukan') - ->from('gadai'); - }) - ->get()->toArray(); - // dd($senaraisag); - - foreach($senaraisag as $data) + + $getcaw = Simulasi::where('simulasibid.simulasi_id', $simulasi_id)->get(); + dd($getcaw); + foreach($getcaw as $caw) { - //insert lelong_tebus - $lelongtebus = new LelongTebus; - $lelongtebus->tarikh = $currentdate; - $lelongtebus->kodcaw = $data['kodcaw']; - $lelongtebus->teller = $user->name; - $lelongtebus->norujukan = $data['norujukan']; - $lelongtebus->batch_no = $simulasi_id; - $lelongtebus->nilaimarhun = $data['nilaimarhun']; - $lelongtebus->pinjaman = $data['pinjaman']; - $lelongtebus->upah = $data['bakiupah']; - $lelongtebus->jbg = $data['jbg']; - $lelongtebus->jenis_tebus = 'T'; - $lelongtebus->save(); + $bycaw = + $senaraisag = SimulasiBid::where('simulasibid.simulasi_id', $simulasi_id) + ->whereNotIn('simulasibid.norujukan', function($datagadai) { + $datagadai = Gadai::all(); + }) + ->get()->toArray(); + dd($senaraisag); - // dd($data['norujukan']); - $updatesimulasi = SimulasiBid::where('norujukan','=',$data['norujukan'])->first(); - $updatesimulasi->delete(); - //insert loguser - $loguser = new LogUser; - $loguser->user_id = $user->id; - $loguser->date = $currentdate; - $loguser->username = $user->username; - $loguser->nama_user = $user->name; - $loguser->norujukan = $data['norujukan']; - $loguser->nota = ' Kemaskini Data Simulasi '.$simulasi_id; - $loguser->save(); + foreach($senaraisag as $data) + { + //insert lelong_tebus + $lelongtebus = new LelongTebus; + $lelongtebus->tarikh = $currentdate; + $lelongtebus->kodcaw = $data['kodcaw']; + $lelongtebus->teller = $user->name; + $lelongtebus->norujukan = $data['norujukan']; + $lelongtebus->batch_no = $simulasi_id; + $lelongtebus->nilaimarhun = $data['nilaimarhun']; + $lelongtebus->pinjaman = $data['pinjaman']; + $lelongtebus->upah = $data['bakiupah']; + $lelongtebus->jbg = $data['jbg']; + $lelongtebus->jenis_tebus = 'T'; + $lelongtebus->save(); + + // dd($data['norujukan']); + $updatesimulasi = SimulasiBid::where('norujukan','=',$data['norujukan'])->first(); + $updatesimulasi->delete(); + //insert loguser + $loguser = new LogUser; + $loguser->user_id = $user->id; + $loguser->date = $currentdate; + $loguser->username = $user->username; + $loguser->nama_user = $user->name; + $loguser->norujukan = $data['norujukan']; + $loguser->nota = ' Kemaskini Data Simulasi '.$simulasi_id; + $loguser->save(); + } + + $datatempoh = []; + $senaraisagtempoh = SimulasiBid::join('gadai','gadai.norujukan','=','simulasibid.norujukan') + ->where('simulasibid.simulasi_id', $simulasi_id) + ->whereIn('simulasibid.norujukan', function($query) { + $query->select('norujukan') + ->from('gadai'); + }) + ->select('gadai.tempoh','gadai.tempohbayar','gadai.kadarupah','gadai.norujukan','gadai.tempoh','gadai.bakipjm') + ->get()->toArray(); + // dd($senaraisagtempoh); + + foreach($senaraisagtempoh as $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); + //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; + $loguser->date = $currentdate; + $loguser->username = $user->username; + $loguser->nama_user = $user->name; + $loguser->norujukan = $datatempoh['norujukan']; + $loguser->nota = $simulasi_id.' Kemaskini Tempoh/Bakipjm/Keuntungan' ; + $loguser->save(); + } + + + + $date = Carbon::now()->toDateTimeString(); + $simulasi = Simulasi::where('id','=',$simulasi_id)->first(); + $simulasi->masakemaskini_data = $date; + $simulasi->save(); + + return redirect()->route('analisa.senaraisimulasi') + ->with('success','Kemaskini Berjaya'); } - - $datatempoh = []; - $senaraisagtempoh = SimulasiBid::join('gadai','gadai.norujukan','=','simulasibid.norujukan') - ->where('simulasibid.simulasi_id', $simulasi_id) - ->whereIn('simulasibid.norujukan', function($query) { - $query->select('norujukan') - ->from('gadai'); - }) - ->select('gadai.tempoh','gadai.tempohbayar','gadai.kadarupah','gadai.norujukan','gadai.tempoh','gadai.bakipjm') - ->get()->toArray(); - // dd($senaraisagtempoh); - - foreach($senaraisagtempoh as $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); - //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; - $loguser->date = $currentdate; - $loguser->username = $user->username; - $loguser->nama_user = $user->name; - $loguser->norujukan = $datatempoh['norujukan']; - $loguser->nota = $simulasi_id.' Kemaskini Tempoh/Bakipjm/Keuntungan' ; - $loguser->save(); - } - - - - $date = Carbon::now()->toDateTimeString(); - $simulasi = Simulasi::where('id','=',$simulasi_id)->first(); - $simulasi->masakemaskini_data = $date; - $simulasi->save(); - - 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') + $arraylistgadai = 0; + $marhun = SimulasiBid::join('cawangan', 'simulasibid.caw_id', '=', 'cawangan.id') ->where('simulasi_id','=',$simulasi_id) - ->where('caw_id','=',$cawid) - ->groupBy('gadai.nokp') - ->select('gadai.nokp') - ->get()->toArray(); - // dd($marhuns); + ->where('caw_id','=',$cawid); - foreach($marhuns as $index1=>$cal){ - $customer = Customer::on('mysql2') - ->where('kpbaru','=',$cal['nokp']) + $arraynorujukan = $marhun->pluck('norujukan')->toArray(); + $datasimulasi = $marhun->get(); + $marhuns = Gadai::on($datasimulasi[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan) + ->select('nokp') + ->groupBy('nokp')->get(); + // dd($datagadai); + $arraysag = []; + + foreach($marhuns as $index1=>$cal) + { + $customer = Customer::where('kpbaru','=',$cal['nokp']) ->orWhere('kplama','=',$cal['nokp']) ->first(); + // dd($customer); - $listsag = SimulasiBid::join('gadai', 'gadai.norujukan','=','simulasibid.norujukan') - ->where('gadai.nokp','=',$cal['nokp']) + $listsag = Gadai::on($datasimulasi[0]['kodcaw'])->whereIn('norujukan', $arraynorujukan) + ->where('nokp','=',$cal['nokp']) ->get(); + // dd($listgadai); + foreach($listsag as $index=>$listing){ + $ktlhbyr = TransaksiKeuntungan::on('main')->where('norujukan','=',$listing['norujukan'])->sum('bayaran_keuntungan'); + // dd($ktlhbyr); + $total_untung_rebet = TransaksiKeuntungan::on('main')->where('norujukan','=',$listing['norujukan'])->sum('keuntungan_rebet'); + $total_untung_asal = TransaksiKeuntungan::on('main')->where('norujukan','=',$listing['norujukan'])->sum('bayaran_keuntungan'); + $beza_keuntungan = $total_untung_asal - $total_untung_rebet; + $keuntungan = bcdiv(($listing['tempoh']-$listing['tempohbayar'])*$listing['kadarupah']/100*$listing['bakipjm'],1,1)-$beza_keuntungan; + // dd($keuntungan); + $listsag[$index]['ktlhbyr'] = $ktlhbyr; + $listsag[$index]['keuntungan'] = $keuntungan; + } + + + + + + + + // $listsag = SimulasiBid::join($dbname.'.gadai as db2','SimulasiBid.norujukan','=','db2.norujukan') + // ->where('db2.nokp','=',$cal['nokp']) + // ->where('SimulasiBid.simulasi_id','=',$simulasi_id) + // ->get(); // dd($listsag); // $keuntungan = $cal['bakipjm'] - ($cal['bakihargajualan'] - ($cal['upah12'] - $cal['ansakhir'])-(($cal['tempoh']-$cal['tempohbayar'])*$cal['kadarupah']/100*$cal['bakipjm']) ); @@ -1173,8 +1223,13 @@ class SimulasiController extends Controller $marhuns[$index1]['nama'] = $customer; $marhuns[$index1]['listsag'] = $listsag; + // array_push($arraylistgadai,[ + // 'hargaasas' => $cal[0]['hargaasas'] + + // ]); + } - return view('simulasi.listsagbycust',compact('marhuns','simulasi_id','cawid','listsag')); + return view('simulasi.listsagbycust',compact('marhuns','simulasi_id','cawid','ktlhbyr')); } } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 443204a7..a7dc8963 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 $connection = 'main'; protected $table = 'customer'; protected $fillable = [ diff --git a/resources/views/includes/sidebar.blade.php b/resources/views/includes/sidebar.blade.php index 1eb03aeb..777b7d4b 100644 --- a/resources/views/includes/sidebar.blade.php +++ b/resources/views/includes/sidebar.blade.php @@ -157,9 +157,9 @@
{{ $message }}
+{{ $message }}
@endif +