diff --git a/app/Coordination.php b/app/Coordination.php new file mode 100644 index 0000000..b95c6e1 --- /dev/null +++ b/app/Coordination.php @@ -0,0 +1,39 @@ +json($total); } diff --git a/app/Http/Controllers/LaporanController.php b/app/Http/Controllers/LaporanController.php index 75753e2..485ed9e 100644 --- a/app/Http/Controllers/LaporanController.php +++ b/app/Http/Controllers/LaporanController.php @@ -1699,4 +1699,18 @@ class LaporanController extends Controller return $response; } + + public function getPenyelarasan($kodcaw,Request $request){ + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $response = Coordination::on($cawangan['mysql'])->where('tarikh',$request->tarikh)->first()->toArray(); + + if($response){ + return response()->json($response,200); + }else{ + return response('notfound'); + } + } + } diff --git a/app/Http/Controllers/PenyelarasanController.php b/app/Http/Controllers/PenyelarasanController.php new file mode 100644 index 0000000..bc29f52 --- /dev/null +++ b/app/Http/Controllers/PenyelarasanController.php @@ -0,0 +1,19 @@ +where('kodcaw',$kodcaw)->first(); + $coordination = Coordination::on($cawangan['mysql'])->where('date',$request->tarikh)->get(); + + return response()->json($coordination); + } +} diff --git a/app/Http/Controllers/Reports/OnePercentController.php b/app/Http/Controllers/Reports/OnePercentController.php index bea2ea4..9abb086 100644 --- a/app/Http/Controllers/Reports/OnePercentController.php +++ b/app/Http/Controllers/Reports/OnePercentController.php @@ -2,10 +2,17 @@ namespace App\Http\Controllers\Reports; +use App\Cawangan; +use App\Gadai; use App\Http\Controllers\Controller; use App\Services\Reports\OnePercentService as ReportOne; use App\TransaksiKeuntungan; +use Carbon\Carbon; use Illuminate\Http\Request; + +use App\Support\v1\Calculation as V1Calculation; +use App\Support\v2\Calculation as V2Calculation; + use Lcobucci\JWT\Signer\Rsa; class OnePercentController extends Controller @@ -89,4 +96,138 @@ class OnePercentController extends Controller return response()->json($response); } + + public function getStokAuditBackdate(Request $request){ + $cawangan = Cawangan::where('kodcaw','KB2')->first(); + $tarikh = '2024-02-01'; + + $akrual = Gadai::on($cawangan['mysql']) + ->where([['tagpalsu','=',0],['t_gadai','<=',$tarikh],['sttebus','=','']]) + ->orWhere([['tagpalsu','=',0],['t_update','>',$tarikh],['sttebus','!=',''],['t_gadai','<=',$tarikh]]) + ->orderBy('t_gadai', 'ASC') + ->orderBy('sirig', 'ASC') + ->get(); + + $chunkSize = 100; + $summationonepercent = 0; + $summationujrah = 0; + $summationupah = 0; + $count = 0; + $summationbkpjm = 0; + $array_test = []; + + $akrual->chunk($chunkSize)->each(function ($chunk) use(&$summationupah,&$array_test,$tarikh,&$summationonepercent,&$summationujrah,&$count,&$summationbkpjm) { + // Process each chunk of items + foreach ($chunk as $item) { + $sagbaru = ($item->tagbaru) ? true : false; + $trans_keun = TransaksiKeuntungan::on('mysql7')->where([['norujukan','=',$item->norujukan],['bayaran_pembiayaan','>=',0]])->whereDate('tarikh_bayaran','<=',$tarikh)->get(); + + if($sagbaru == false){ + $tawarruqservices = new V1Calculation(); + }else{ + $calculation = new V2Calculation(); + } + + if($trans_keun->isNotEmpty()){ + $bakipinjaman = $item->pinjaman; + $last_transaction = Carbon::parse($trans_keun->last()->tarikh_bayaran)->toDateString(); + if($last_transaction > $tarikh){ + $last_transaction = $tarikh; + } + + $trans_keun->each(function($trans) use(&$bakipinjaman){ + $bakipinjaman -= $trans['bayaran_pembiayaan']; + }); + + + + $kiraan = ($sagbaru) ? $calculation->kiraanKeuntunganRebet($bakipinjaman,$item->nilaimarhun,$item->kadarupah,(($bakipinjaman/$item->nilaimarhun) * 100)) : $tawarruqservices->kiraanTawarruq($bakipinjaman,$item->kadarupah); + $tempoh = $this->kiraanTarikhJBG($item->t_gadai,$tarikh); + $tempoh_last_transaction = $this->kiraanTarikhJBG($item->t_gadai,$last_transaction); + $tempoh_belum_bayar = $tempoh - $tempoh_last_transaction; + + if($sagbaru){ + $onepercent = $calculation->getRoundedMethod($kiraan['onepercent'] * $tempoh_belum_bayar); + $ujrah = $calculation->getRoundedMethod($kiraan['ujrah'] * $tempoh_belum_bayar); + $summationonepercent += $onepercent; + $summationujrah += $ujrah; + $summationbkpjm += $bakipinjaman; + array_push($array_test,['norujukan' => $item->norujukan,'ujrah' => $ujrah,'onepercent' => $onepercent,'pinjaman' => $item->pinjaman, 'bakipjm' => $bakipinjaman,'tempoh' => $tempoh_belum_bayar]); + }else{ + $upahsemasa_raw = $tempoh_belum_bayar * $kiraan; + + $upah_semasa_round = number_format($upahsemasa_raw,2); + $upah_semasa = substr($upah_semasa_round, 0, -1); + if(strpos($upah_semasa,',')){ + $upah_semasa = str_replace(',','',$upah_semasa); + } + + $summationupah += $upah_semasa; + + array_push($array_test,['norujukan' => $item->norujukan,'upah' => $upah_semasa,'pinjaman' => $item->pinjaman, 'bakipjm' => $item->pinjaman,'tempoh' => $tempoh_belum_bayar]); + } + + }else{ + + $kiraan = ($sagbaru) ? $calculation->kiraanKeuntunganRebet($item->pinjaman,$item->nilaimarhun,$item->kadarupah,(($item->pinjaman/$item->nilaimarhun) * 100)) : $tawarruqservices->kiraanTawarruq($item->pinjaman,$item->kadarupah); + $tempoh = $this->kiraanTarikhJBG($item->t_gadai,$tarikh); + + if($sagbaru){ + $onepercent = $calculation->getRoundedMethod($kiraan['onepercent'] * $tempoh); + $ujrah = $calculation->getRoundedMethod($kiraan['ujrah'] * $tempoh); + $summationonepercent += $onepercent; + $summationujrah += $ujrah; + $summationbkpjm += $item->pinjaman; + + array_push($array_test,['norujukan' => $item->norujukan,'ujrah' => $ujrah,'onepercent' => $onepercent,'pinjaman' => $item->pinjaman, 'bakipjm' => $item->pinjaman,'tempoh' => $tempoh]); + }else{ + $upahsemasa_raw = $tempoh * $kiraan; + $upah_semasa_round = number_format($upahsemasa_raw,2); + $upah_semasa = substr($upah_semasa_round, 0, -1); + if(strpos($upah_semasa,',')){ + $upah_semasa = str_replace(',','',$upah_semasa); + } + $summationupah += $upah_semasa; + array_push($array_test,['norujukan' => $item->norujukan,'upah' => $upah_semasa,'pinjaman' => $item->pinjaman, 'bakipjm' => $item->pinjaman,'tempoh' => $tempoh]); + } + + } + $count++; + + } + }); + + return response()->json($array_test); + + } + + private function kiraanTarikhJBG($tarikhgadai,$tarikh){ + $tarikh_gadai = Carbon::parse($tarikhgadai. ' 00:00:00'); + $tarikh = new Carbon($tarikh); + $tahun_gadai = $tarikh_gadai->year; + $bulan_gadai = $tarikh_gadai->month; + $hari_gadai = $tarikh_gadai->day; + $tahun_semasa = $tarikh->year; + $bulan_semasa = $tarikh->month; + $hari_semasa = $tarikh->day; + if($hari_semasa >= $hari_gadai){ + $beza_hari = $hari_semasa - $hari_gadai + 1; + }else if($hari_semasa < $hari_gadai){ + $bulan_semasa = $bulan_semasa - 1; + $beza_hari = ($hari_semasa + 30) - $hari_gadai + 1; + } + $extensivemonth_gadai = 0; + if($beza_hari >= 1 && $beza_hari <= 15){ + $extensivemonth_gadai = 0.5; + }else if($beza_hari >= 16){ + $extensivemonth_gadai = 1; + }else{ + $extensivemonth_gadai = 0; + } + $beza_tahun = $tahun_semasa - $tahun_gadai; + $beza_bulan = ($bulan_semasa + ($beza_tahun * 12)) - $bulan_gadai; + $tempoh_gadai = $beza_bulan + $extensivemonth_gadai; + + return $tempoh_gadai; + } } diff --git a/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index 75e2511..a0e92a4 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -1488,7 +1488,7 @@ class TebusController extends Controller $bukanansuran = 0; if($bukanansuran_data){ foreach($bukanansuran_data as $index=>$bukanansuranData){ - $gadaiData = Gadai::on($cawangan['mysql'])->where([['norujukan',$bukanansuranData['norujukan']],['hargajualan','<>',null]])->first(); + $gadaiData = Gadai::on($cawangan['mysql'])->where([['norujukan',$bukanansuranData['norujukan']],['hargajualan','<>',null],['tagbaru',0]])->first(); if($gadaiData){ $bukanansuran += $bukanansuranData['keuntungan_rebet']; } @@ -1756,6 +1756,7 @@ class TebusController extends Controller }else if($calculate_month < 0){ $jumlahakru = AkruNet::on($cawangan['mysql']) ->where('bulan','<=',$intmonth_sekarang) + ->where('tahun',$year) ->sum('jumlah'); return response()->json($jumlahakru); diff --git a/app/Services/Reports/OnePercentService.php b/app/Services/Reports/OnePercentService.php index ab366f9..f839599 100644 --- a/app/Services/Reports/OnePercentService.php +++ b/app/Services/Reports/OnePercentService.php @@ -71,37 +71,38 @@ class OnePercentService $keuntungan = TransaksiKeuntungan::on('mysql7') ->whereIn('norujukan',$norujukan) ->sum('onepercent_rebet'); + }else{ - $akrual = Gadai::on($this->cawangan['mysql']) - ->where([['tagpalsu','=',0],['t_gadai','<=',$start],['sttebus','=',''],['tagbaru',1]]) - ->orWhere([['tagbaru',1],['tagpalsu','=',0],['t_update','>',$start],['sttebus','!=',''],['t_gadai','<=',$start]]) - ->orderBy('t_gadai', 'ASC') - ->orderBy('sirig', 'ASC') - ->get(); + // $akrual = Gadai::on($this->cawangan['mysql']) + // ->where([['tagpalsu','=',0],['t_gadai','<=',$start],['sttebus','=',''],['tagbaru',1]]) + // ->orWhere([['tagbaru',1],['tagpalsu','=',0],['t_update','>',$start],['sttebus','!=',''],['t_gadai','<=',$start]]) + // ->orderBy('t_gadai', 'ASC') + // ->orderBy('sirig', 'ASC') + // ->get(); - $keuntungan = $this->calculateTotalProfit($akrual,$start); - $keuntungan = $keuntungan['onepercent']; + // $keuntungan = $this->calculateTotalProfit($akrual,$start); + // $keuntungan = $keuntungan['onepercent']; + $formData = [ + 'kodcaw' => $this->cawangan['kodcaw'], + 'tarikh' => $start, + ]; + + $request = new Request($formData); + + $akru = $this->calculateAccruedIncome($request); + + $keuntungan = $akru['accrual_income_onepercent']; } return $keuntungan; }else if($type == 'L'){ - $akrual = Gadai::on($this->cawangan['mysql'])->where([['sttebus',''],['tagbaru',1],['t_update','>=',$start],['t_update','<=',$end]])->sum('tunggakanonepercent'); - - $norujukan = Gadai::on($this->cawangan['mysql'])->where('sttebus','T')->where('tagbaru',1)->where('t_update','>=',$start)->where('t_update','<=',$end)->pluck('norujukan'); - - - //Keuntungan Pada Bukan Bulan Yang Sama - $keuntungan = TransaksiKeuntungan::on('mysql7') - ->whereIn('norujukan',$norujukan) - ->whereDate('tarikh_bayaran','>=',$start) - ->whereDate('tarikh_bayaran','<=',$end) - ->sum('onepercent_rebet'); + /* Keuntungan Semasa */ + $keuntungan_semasa = $this->CurrentProfit($start,$end,$this->cawangan['kodcaw']); + $totalkeuntungan=$keuntungan_semasa['onepercent']; } - $totalkeuntungan = $keuntungan + $akrual; - return $totalkeuntungan; } @@ -125,31 +126,35 @@ class OnePercentService ->whereIn('norujukan',$norujukan) ->sum('ujrah_rebet'); }else{ - $akrual = Gadai::on($this->cawangan['mysql']) - ->where([['tagpalsu','=',0],['t_gadai','<=',$start],['sttebus','=',''],['tagbaru',1]]) - ->orWhere([['tagbaru',1],['tagpalsu','=',0],['t_update','>',$start],['sttebus','!=',''],['t_gadai','<=',$start]]) - ->orderBy('t_gadai', 'ASC') - ->orderBy('sirig', 'ASC') - ->get(); + // $akrual = Gadai::on($this->cawangan['mysql']) + // ->where([['tagpalsu','=',0],['t_gadai','<=',$start],['sttebus','=',''],['tagbaru',1]]) + // ->orWhere([['tagbaru',1],['tagpalsu','=',0],['t_update','>',$start],['sttebus','!=',''],['t_gadai','<=',$start]]) + // ->orderBy('t_gadai', 'ASC') + // ->orderBy('sirig', 'ASC') + // ->get(); - $keuntungan = $this->calculateTotalProfit($akrual,$start); - $keuntungan = $keuntungan['ujrah']; + // $keuntungan = $this->calculateTotalProfit($akrual,$start); + // $keuntungan = $keuntungan['ujrah']; + + $formData = [ + 'kodcaw' => $this->cawangan['kodcaw'], + 'tarikh' => $start, + ]; + + $request = new Request($formData); + + $akru = $this->calculateAccruedIncome($request); + + $keuntungan = $akru['accrual_income_ujrah']; } return $keuntungan; }else if($type == 'L'){ - $akrual = Gadai::on($this->cawangan['mysql'])->where([['sttebus',''],['tagbaru',1],['t_update','>=',$start],['t_update','<=',$end]])->sum('tunggakanujrah'); - - $norujukan = Gadai::on($this->cawangan['mysql'])->where('sttebus','T')->where('tagbaru',1)->pluck('norujukan'); - - $ujrah = TransaksiKeuntungan::on('mysql7') - ->whereIn('norujukan',$norujukan) - ->whereDate('tarikh_bayaran','>=',$start) - ->whereDate('tarikh_bayaran','<=',$end) - ->sum('ujrah_rebet');; + /* Keuntungan Semasa */ + $keuntungan_semasa = $this->CurrentProfit($start,$end,$this->cawangan['kodcaw']); + $totalujrah = $keuntungan_semasa['ujrah']; } - $totalujrah = $ujrah + $akrual; return $totalujrah; } diff --git a/app/Support/v2/Penebusan.php b/app/Support/v2/Penebusan.php index d2f0582..609ffa6 100644 --- a/app/Support/v2/Penebusan.php +++ b/app/Support/v2/Penebusan.php @@ -587,6 +587,9 @@ class Penebusan 'duit_masuk' => $request->bakiupah, 'created_at' => $current, 'bakiharga' => $baki_hargajualan, + 'nowakil' => (int)$request->nowakil, + 'duitpelanggan' => isset($request->duitpelanggan) ? $request->duitpelanggan : 0, + 'bakipelanggan' => $request->bakipelanggan ]); }else{ $baki_hargajualan = $gadai['bakihargajualan'] - $request->bakipinjaman; diff --git a/database/migrations/2024_05_06_230512_create_coordination_table.php b/database/migrations/2024_05_06_230512_create_coordination_table.php new file mode 100644 index 0000000..51d2640 --- /dev/null +++ b/database/migrations/2024_05_06_230512_create_coordination_table.php @@ -0,0 +1,71 @@ +getPdo(); + return true; + } catch(\Exception $e){ + return false; + } + }); + return $db_connection; + } + + public function up() + { + + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + + if (!Schema::connection($dbase)->hasTable('coordination')) { + Schema::connection($dbase)->create('coordination', function (Blueprint $table) { + $table->id(); + $table->string('details',50); + $table->string('glcode',10); + $table->string('jenis',20); + $table->date('date')->nullable(); + $table->integer('reg_user_id'); + $table->integer('ver_op_user_id'); + $table->integer('ver_acc_user_id'); + $table->decimal('amount', 9, 2); + $table->timestamps(); + }); + } + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach($db_connection as $dbase){ + + Schema::connection($dbase)->dropIfExists('akru_net_pecahan'); + }; + } +} diff --git a/routes/report.php b/routes/report.php index 64d865f..29aa4e6 100644 --- a/routes/report.php +++ b/routes/report.php @@ -23,5 +23,6 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) { $router->get('getaccrualincome/all',['uses' => 'OnePercentController@getAllCawanganAccruedIncome']); $router->get('getTotalCurrentProfit/{kod_cawangan}', ['uses' => 'OnePercentController@getCurrentProfit']); + $router->get('stokaudit/get',['uses' => 'OnePercentController@getStokAuditBackdate']); }); }); diff --git a/routes/web.php b/routes/web.php index df8e92f..9052705 100644 --- a/routes/web.php +++ b/routes/web.php @@ -547,6 +547,10 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('Lejer/PendapatanAkrual/{kodcaw}',['uses'=>'LaporanController@SemakanPendapatanAkrual']); $router->get('Backup/ImbangDuga/{kodcaw}',['uses'=>'LaporanController@SemakanBackupImbangDuga']); + /* Penyelarasan */ + $router->get('penyelarasan/{kodcaw}',['uses'=>'PenyelarasanController@getPenyelarasan']); + + //END IMBANG DUGA & LEJER AM// //ADDED LEJER AM