diff --git a/app/Http/Controllers/GadaiController.php b/app/Http/Controllers/GadaiController.php index 0125752..4304063 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -1639,18 +1639,24 @@ class GadaiController extends Controller $cawangan_all = Cawangan::on('mysql7')->get(); $current = Carbon::now(); $current = new Carbon(); + $harini = $current->toDateString(); + $lastweek = $current->subWeek()->toDateString(); $gadaiToday = 0; + $gadaiLastweek = 0; foreach($cawangan_all as $index=>$cawangan){ - $gadai = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$current->toDateString())->get(); - if(sizeof($gadai) != 0){ - foreach($gadai as $gadaiall) - { - $gadaiToday += $gadaiall['pinjaman']; - } - } + $gadai = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$harini)->sum('pinjaman'); + $gadai_last_week = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$lastweek)->sum('pinjaman'); + $gadaiLastweek += $gadai_last_week; + $gadaiToday += $gadai; } + $diffGadaiPercent = 0; + if($gadaiLastweek != 0){ + $diffGadaiPercent = (($gadaiToday - $gadaiLastweek)/$gadaiLastweek)*100; + } + $dataGadai = []; + array_push($dataGadai,['gadaiToday'=>$gadaiToday,'percentDiff'=>$diffGadaiPercent]); - return response()->json(number_format($gadaiToday,2)); + return response()->json($dataGadai); } @@ -1659,17 +1665,24 @@ class GadaiController extends Controller $cawangan_all = Cawangan::on('mysql7')->get(); $current = Carbon::now(); $current = new Carbon(); + $harini = $current->toDateString(); + $lastweek = $current->subWeek()->toDateString(); $tebusToday = 0; + $tebusLastWeek = 0; foreach($cawangan_all as $index=>$cawangan){ - $tebus = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$current->toDateString())->get(); - if(sizeof($tebus) != 0){ - foreach($tebus as $tebusall) - { - $tebusToday += $tebusall['pinjaman']; - } - } + $tebus = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$harini)->sum('bakipjm'); + $tebus_last_week = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$lastweek)->sum('bakipjm'); + + $tebusToday += $tebus; + $tebusLastWeek += $tebus_last_week; } - return response()->json(number_format($tebusToday,2)); + $diffTebusPercent = 0; + if($tebusLastWeek != 0){ + $diffTebusPercent = (($tebusToday - $tebusLastWeek)/$tebusLastWeek)/100; + } + $dataTebus = []; + array_push($dataTebus,['tebusToday'=>$tebusToday,'percentDiff'=>$diffTebusPercent]); + return response()->json($dataTebus); } public function showAllVariasiToday(){ @@ -1677,46 +1690,64 @@ class GadaiController extends Controller $cawangan_all = Cawangan::on('mysql7')->get(); $current = Carbon::now(); $current = new Carbon(); - $variasiToday = 0; + $harini = $current->toDateString(); + $lastweek = $current->subWeek()->toDateString(); $tebusToday = 0; - foreach($cawangan_all as $index=>$cawangan){ - $tebus = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$current->toDateString())->get(); - if(sizeof($tebus) != 0){ - foreach($tebus as $tebusall) - { - $tebusToday += $tebusall['pinjaman']; - } - } - } $gadaiToday = 0; + $tebusLastWeek = 0; + $gadaiLastWeek = 0; foreach($cawangan_all as $index=>$cawangan){ - $gadai = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$current->toDateString())->get(); - if(sizeof($gadai) != 0){ - foreach($gadai as $gadaiall) - { - $gadaiToday += $gadaiall['pinjaman']; - } - } + $tebus = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$harini)->sum('bakipjm'); + $gadai = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$harini)->sum('pinjaman'); + $gadai_last_week = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$lastweek)->sum('pinjaman'); + $tebus_last_week = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$lastweek)->sum('bakipjm'); + + $tebusToday += $tebus; + $gadaiToday += $gadai; + $tebusLastWeek += $tebus_last_week; + $gadaiLastWeek += $gadai_last_week; } $variasiToday = $gadaiToday - $tebusToday; - return response()->json(number_format($variasiToday,2)); + $variasiLastWeek = $gadaiLastWeek - $tebusLastWeek; + $percentDiffVariasi = 0; + if($variasiLastWeek != 0){ + $percentDiffVariasi = (($variasiToday - $variasiLastWeek)/$variasiLastWeek)*100; + } + $dataVariasi = []; + array_push($dataVariasi,['variasiToday'=>$variasiToday,'percentVariasi'=>$percentDiffVariasi]); + return response()->json($dataVariasi); } public function showAllUpahToday(){ $cawangan_all = Cawangan::on('mysql7')->get(); $current = Carbon::now(); $current = new Carbon(); + $harini = $current->toDateString(); + $lastweek = $current->subWeek()->toDateString(); $upahToday = 0; + $upahLastWeek = 0; foreach($cawangan_all as $index=>$cawangan){ - $upah = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$current->toDateString())->get(); - if(sizeof($upah) != 0){ - foreach($upah as $upahall) - { - $upahToday += $upahall['bakiupah']; - } - } + $upah_tebus_today = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$harini)->sum('bakiupah'); + $upah_today = Advansur::on($cawangan['mysql'])->where('tarikh',$harini)->sum('upahDibayar'); + + $upah_tebus_lastweek = Tebus::on($cawangan['mysql'])->where('t_tebus','=',$lastweek)->sum('bakiupah'); + $upah_lastweek = Advansur::on($cawangan['mysql'])->where('tarikh',$lastweek)->sum('upahDibayar'); + + $upahToday = $upahToday + $upah_tebus_today + $upah_today; + $upahLastWeek = $upahLastWeek + $upah_tebus_lastweek + $upah_lastweek; } - return response()->json(number_format($upahToday,2)); + $ansuran_today = TransaksiKeuntungan::on('mysql7')->where([['tarikh_bayaran','>=',$harini . ' 00:00:00'],['tarikh_bayaran','<=',$harini . ' 23:59:59']])->sum('bayaran_keuntungan'); + $ansuran_lastweek = TransaksiKeuntungan::on('mysql7')->where([['tarikh_bayaran','>=',$lastweek . ' 00:00:00'],['tarikh_bayaran','<=',$lastweek . ' 23:59:59']])->sum('bayaran_keuntungan'); + + $upahToday = $upahToday + $ansuran_today; + $upahLastWeek = $upahLastWeek + $ansuran_lastweek; + $diffUpah = 0; + if($upahLastWeek != 0){ + $diffUpah = (($upahToday - $upahLastWeek)/$upahLastWeek)*100; + } + $upahData = []; + array_push($upahData,['upahToday'=>$upahToday,'percentDiff'=>$diffUpah]); + return response()->json($upahData); } public function showAllGadaiTerkumpul(){ $cawangan_all = Cawangan::on('mysql7')->get(); @@ -1791,12 +1822,92 @@ class GadaiController extends Controller $cawangan_all = Cawangan::on('mysql7')->get(); $current = Carbon::now(); $current = new Carbon(); + $harini = $current->toDateString(); + $lastweek = $current->subWeek()->toDateString(); $outstandingSemasa = 0; + $outstandingLastWeek = 0; foreach($cawangan_all as $index=>$cawangan){ - $gadaiterkumpul = Gadai::on($cawangan['mysql'])->where('sttebus','=','')->sum('pinjaman'); - $outstandingSemasa += $gadaiterkumpul; + $gadaiactivetawarruq = Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['hargajualan','<>',null]])->sum('bakipjm'); + $gadaiactivearrahn = Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['hargajualan',null]])->sum('pinjaman'); + + $gadaiactivetawarruqLastWeek = Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['hargajualan','<>',null],['t_gadai','<=',$lastweek]])->sum('bakipjm'); + $gadaiactivearrahnLastWeek = Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['hargajualan',null],['t_gadai','<=',$lastweek]])->sum('pinjaman'); + + $totalgadaiactive = $gadaiactivetawarruq + $gadaiactivearrahn; + $totalgadaiactiveLastWeek = $gadaiactivetawarruqLastWeek + $gadaiactivearrahnLastWeek; + + $outstandingSemasa += $totalgadaiactive; + $outstandingLastWeek += $totalgadaiactiveLastWeek; } - return response()->json(number_format($outstandingSemasa,2)); + $percentDiffOutstanding = 0; + if($outstandingLastWeek != 0){ + $percentDiffOutstanding = (($outstandingSemasa - $outstandingLastWeek)/$outstandingLastWeek)*100; + } + $dataOutstanding = []; + array_push($dataOutstanding,['outstandingToday'=>$outstandingSemasa,'percentOutstanding'=>$percentDiffOutstanding]); + return response()->json($dataOutstanding); + } + + public function oneWeekData(){ + $weekly = Carbon::now(); + $weekly = new Carbon(); + $cawangan_all = Cawangan::on('mysql7')->get(); + $dataOneWeek = []; + for($i=0;$i<7;$i++){ + if($i == 0){ + $weekly_array_date = $weekly->subDays(0); + }else{ + $weekly_array_date = $weekly->subDays(1); + } + array_push($dataOneWeek,['tarikh'=>$weekly_array_date->toDateString(),'totalpembiayaan'=>0,'totaltebus'=>0,'totalupah'=>0, 'totalkomoditi'=>0,'totalnilaimarhun'=>0,'onlinepayment'=>0,'hargaemas'=>0]); + } + + foreach($dataOneWeek as $index=>$oneWeek){ + $totalGadai = 0; + $totalTebus = 0; + $totalUpah = 0; + $totalKomoditi = 0; + $totalNilaiMarhun = 0; + $totalOnline = 0; + $upah = 0; + + foreach($cawangan_all as $index2=>$cawangan){ + $gadaiCawangan = Gadai::on($cawangan['mysql'])->where('t_gadai',$oneWeek['tarikh'])->sum('pinjaman'); + $tebusCawangan = Tebus::on($cawangan['mysql'])->where('t_tebus',$oneWeek['tarikh'])->sum('bakipjm'); + $upahTebusCawangan = Tebus::on($cawangan['mysql'])->where('t_tebus',$oneWeek['tarikh'])->sum('bakiupah'); + $nilaiMarhunCawangan = Gadai::on($cawangan['mysql'])->where('t_gadai',$oneWeek['tarikh'])->sum('nilaimarhun'); + $upahCawangan = Advansur::on($cawangan['mysql'])->where('tarikh',$oneWeek['tarikh'])->sum('upahDibayar'); + + $totalGadai += $gadaiCawangan; + $totalTebus += $tebusCawangan; + $totalNilaiMarhun += $nilaiMarhunCawangan; + $upah_cawangan = $upahTebusCawangan + $upahCawangan; + $upah += $upah_cawangan; + } + $totalOnline = TransactionOnline::on('mysql7')->where([['tarikh',$oneWeek['tarikh']],['status','PAID']])->sum('total_payment'); + $totalKomoditi = KomuditiTransaksi::on('mysql7')->where('tarikh',$oneWeek['tarikh'])->sum('unit_komuditi'); + $ansuran = TransaksiKeuntungan::on('mysql7')->join('transaction as trans', function($join){ + $join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan'); + $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); + }) + ->where('trans.teller','<>','Online') + ->where([['transaksi_keuntungan.tarikh_bayaran','>=',$oneWeek['tarikh'] . ' 00:00:00'],['transaksi_keuntungan.tarikh_bayaran','<=',$oneWeek['tarikh'] . ' 23:59:59']]) + ->sum('bayaran_keuntungan'); + + $harga_emas = HistoryEmasSandaran::on('mysql7')->where([['t_efektif','<=',$oneWeek['tarikh']],['karat','22.0K']])->orderBy('t_efektif','desc')->first(); + + $totalUpah = $ansuran + $upah; + + $dataOneWeek[$index]['totalpembiayaan'] = $totalGadai; + $dataOneWeek[$index]['totaltebus'] = $totalTebus; + $dataOneWeek[$index]['totalupah'] = $totalUpah; + $dataOneWeek[$index]['totalkomoditi'] = $totalKomoditi; + $dataOneWeek[$index]['totalnilaimarhun'] = $totalNilaiMarhun; + $dataOneWeek[$index]['onlinepayment'] = $totalOnline; + $dataOneWeek[$index]['hargaemas'] = $harga_emas['harga']; + } + + return response()->json($dataOneWeek); } public function nilaiMarhunSemasa() diff --git a/app/Http/Controllers/TacExpressPaymentController.php b/app/Http/Controllers/TacExpressPaymentController.php index a955f72..d857b52 100644 --- a/app/Http/Controllers/TacExpressPaymentController.php +++ b/app/Http/Controllers/TacExpressPaymentController.php @@ -25,9 +25,9 @@ class TacExpressPaymentController extends Controller $mobileno = '60139321786'; $messages = 'AR-RAHN PKB ' . $request->cawangan . ' : TAC: ' . $request->otp_token . ' ' . $currentDateTime . '. AR-RAHN CARELINE CENTRE 1300-22-4343'; - $status = Http::get('http://gateway.onewaysms.com.au:10001/api.aspx',[ - 'apiusername' => 'APIQ4LP5EMKXM', - 'apipassword' => 'APIQ4LP5EMKXM7CQOX', + $status = Http::get('http://gateway.onewaysms.com.my:10001/api.aspx',[ + 'apiusername' => 'APIUK330HDAFO', + 'apipassword' => 'APIUK330HDAFOUK330', 'senderid' => 'INFO', 'mobileno' => $mobileno, 'message'=> $messages, diff --git a/routes/web.php b/routes/web.php index cd9f759..149481f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -570,6 +570,8 @@ $router->group(['prefix'=>'dashboard'], function () use ($router){ $router->get('nilaimarhun/semasa',['uses'=>'GadaiController@nilaiMarhunSemasa']); $router->get('vault/semasa',['uses'=>'GadaiController@petiBesiSemasa']); + $router->get('oneweekdata',['uses'=>'GadaiController@oneWeekData']); + $router->post('prestasi/cawangan',['uses'=>'GadaiController@prestasiCawangan']); $router->post('peti_besi',['uses'=>'GadaiController@petiBesiCawangan']);