diff --git a/app/Http/Controllers/AdminPageController.php b/app/Http/Controllers/AdminPageController.php index e7df70f..f6bf1aa 100644 --- a/app/Http/Controllers/AdminPageController.php +++ b/app/Http/Controllers/AdminPageController.php @@ -3143,7 +3143,7 @@ class AdminPageController extends Controller }) ->whereIn('trans.norujukan',$get_norujukan) ->where('transaction.trans_type','T') - ->where('onepercent','=',0) + ->where('margin_semasa','=',0) ->sum('keuntungan_rebet'); $sum_keun_ansuran = Transaction::on('mysql7') @@ -3154,7 +3154,7 @@ class AdminPageController extends Controller }) ->whereIn('trans.norujukan',$get_norujukan) ->where('transaction.trans_type','A') - ->where('onepercent','=',0) + ->where('margin_semasa','=',0) ->sum('bayaran_keuntungan'); $total = $sum_keun_tebus + $sum_keun_ansuran; diff --git a/app/Http/Controllers/GadaiController.php b/app/Http/Controllers/GadaiController.php index 2ed5fb3..8008bb7 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -399,14 +399,14 @@ class GadaiController extends Controller // $upahrebet_raw = $bilang_bln * (($gadai_data['kadarupah']/100 )* $gadai_data['bakipjm']); $upahrebet_raw = $bilang_bln * $upah['keuntungan']; - $upah_rebet_round = number_format($upahrebet_raw,2); - $upah_rebet = substr($upah_rebet_round, 0, -1); - if(strpos($upah_rebet,',')){ - $upah_rebet = str_replace(',','',$upah_rebet); - } + // $upah_rebet_round = number_format($upahrebet_raw,2); + // $upah_rebet = substr($upah_rebet_round, 0, -1); + // if(strpos($upah_rebet,',')){ + // $upah_rebet = str_replace(',','',$upah_rebet); + // } // $upah_rebet = floatval(preg_replace('/[^\d.]/', '', $upah_rebet)); - return $upah_rebet; + return $upahrebet_raw; } public function updateGadaiMarhunOnline($kodcaw,$norujukan,Request $request){ @@ -525,6 +525,8 @@ class GadaiController extends Controller } $bilang_bln = $tempoh - $gadai['tempohbayar']; + $rounded = $upahsemasa - (($keuntungan['ujrah'] * $bilang_bln) + ($onepercentasal * $bilang_bln)); + $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ 'norujukan' => $norujukan, 'bayaran_keuntungan' => $upahsemasa, @@ -539,6 +541,7 @@ class GadaiController extends Controller 'tempoh' => $gadai['tempoh'], 'beza_tempoh' => $bilang_bln, 'margin_semasa' => $margin_semasa, + 'rounded' => $rounded, ]); DB::connection($cawangan['mysql'])->transaction(function () use($cawangan,$baki_pinjaman,$current,$norujukan,$gadai,$baki_hargajualan,$lelong_tawarruq,$margin_semasa){ diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index 5e2be53..bdd3c82 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -578,9 +578,10 @@ class LelongController extends Controller if($cawangan['tagarrahnbid'] == 1){ // $lelong = Http::withOptions(['verify' => true])->get('https://niklah.arrahn.com.my/api/portalApi',[ - $lelong = Http::withOptions(['verify' => true])->get('http://adminbid.arrahn/api/portalApi',[ - 'norujukan' => $request->norujukan - ])->json(); + // $lelong = Http::withOptions(['verify' => true])->get('http://adminbid.arrahn/api/portalApi',[ + // 'norujukan' => $request->norujukan + // ])->json(); + $lelong = null; $lelong = ($lelong != null) ? $lelong['lelong'] : []; if( $lelong == null ) { diff --git a/app/Http/Controllers/Reports/OnePercentController.php b/app/Http/Controllers/Reports/OnePercentController.php index 9c51542..01e61d4 100644 --- a/app/Http/Controllers/Reports/OnePercentController.php +++ b/app/Http/Controllers/Reports/OnePercentController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Reports; use App\Http\Controllers\Controller; use App\Services\Reports\OnePercentService as ReportOne; +use App\TransaksiKeuntungan; use Illuminate\Http\Request; class OnePercentController extends Controller @@ -25,6 +26,14 @@ class OnePercentController extends Controller return response()->json($response); } + public function getRoundedImbangDuga(string $kod_cawangan) + { + $reports = new ReportOne($kod_cawangan); + $response = $reports->getTotalRounded('B'); + + return response()->json($response); + } + public function getKeuntunganLejerAm(string $kod_cawangan,Request $request) { $reports = new ReportOne($kod_cawangan); @@ -40,4 +49,22 @@ class OnePercentController extends Controller return response()->json($response); } + + public function getRoundedLejerAm(string $kod_cawangan) + { + $reports = new ReportOne($kod_cawangan); + $response = $reports->getTotalRounded('B'); + + return response()->json($response); + } + + public function getTotalRebate(Request $request){ + $totalrebate = TransaksiKeuntungan::on('mysql7') + ->where('norujukan',$request->norujukan) + ->selectRaw('SUM(ujrah - ujrah_rebet) as ujrah') + ->selectRaw('SUM(onepercent - onepercent_rebet) as onepercent') + ->first(); + + return response()->json($totalrebate); + } } diff --git a/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index f2c4ef2..c031f56 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -65,7 +65,6 @@ class TebusController extends Controller if(strpos($hargatebus,',')){ $hargatebus = str_replace(',','',$hargatebus); } - return response()->json($hargatebus); } @@ -89,7 +88,11 @@ class TebusController extends Controller $hargatebus = str_replace(',','',$hargatebus); } - return $hargatebus; + $rounded = $hargatebus - $harga_tebus; + Log::info([$harga_tebus,$rebet]); + $arrayharga = ['harga' => $hargatebus, 'rounded' => $rounded]; + + return $arrayharga; } public function kiraupahTawarruq($kodcaw,$norujukan,$jeniskeuntungan){ @@ -157,16 +160,16 @@ class TebusController extends Controller } // $upah_rebet = round($upahrebet_raw ,PHP_ROUND_HALF_UP); - $upah_rebet_round = number_format($upahrebet_raw,2); - if(strpos($upah_rebet_round,',')){ - $upah_rebet_round = str_replace(',','',$upah_rebet_round); - } - $upah_rebet = substr($upah_rebet_round, 0, -1); - if(strpos($upah_rebet,',')){ - $upah_rebet = str_replace(',','',$upah_rebet); - } + // $upah_rebet_round = number_format($upahrebet_raw,2); + // if(strpos($upah_rebet_round,',')){ + // $upah_rebet_round = str_replace(',','',$upah_rebet_round); + // } + // $upah_rebet = substr($upah_rebet_round, 0, -1); + // if(strpos($upah_rebet,',')){ + // $upah_rebet = str_replace(',','',$upah_rebet); + // } - return $upah_rebet; + return $upahrebet_raw; } public function kiraUpahRebetSebenar($kodcaw,$norujukan){ @@ -449,15 +452,15 @@ class TebusController extends Controller $rebet_raw =$gadai_data['upah12'] - $transaction_keuntungan - $upah_rebet; // dd($gadai_data['upah12'],$transaction_keuntungan,$upah_rebet,$jeniskeuntungan,$rebet_raw); - $rebet_round = bcdiv(round($rebet_raw,2),1,1); - $rebet_round = number_format($rebet_round,2); + // $rebet_round = bcdiv(round($rebet_raw,2),1,1); + // $rebet_round = number_format($rebet_round,2); - if(strpos($rebet_round,',')){ - $rebet_round = str_replace(',','',$rebet_round); - } - $rebet = substr($rebet_round, 0, -1); - - return $rebet; + // if(strpos($rebet_round,',')){ + // $rebet_round = str_replace(',','',$rebet_round); + // } + // $rebet = substr($rebet_round, 0, -1); + + return $rebet_raw; } public function tebusUpdate($kodcaw,$norujukan,Request $request){ @@ -479,7 +482,7 @@ class TebusController extends Controller $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); - $ujrah=0;$onepercent=0; + $ujrah=0;$onepercent=0;$rounded=0; if($gadai['hargajualan'] == null){ $harga_tebus = $this->hargaTebusNotTawarruq($kodcaw,$norujukan); $upah_tebus = $this->kiraUpahNotTawarruq($kodcaw,$norujukan); @@ -489,7 +492,7 @@ class TebusController extends Controller $harga_tebus = $this->hargaTebusTawarruq($kodcaw,$norujukan,$request->jeniskeuntungan); $upah_tebus = $this->kiraupahTawarruq($kodcaw,$norujukan,$request->jeniskeuntungan); $upah_rebet = $this->kiraUpahRebetSebenar($kodcaw,$norujukan); - $upah_rebet_sebenar = $harga_tebus - $gadai['bakipjm']; + $upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm']; if($request->jeniskeuntungan == 'onepercent'){ $array_onepercent = $this->kiraupahUjrahOnePercent($kodcaw,$norujukan); @@ -515,7 +518,7 @@ class TebusController extends Controller 'pinjaman' => $gadai['pinjaman'], 'ansuran' => 0.00, 'addpinjaman' => $request->addpinjaman, - 'bakipjm' => $harga_tebus, + 'bakipjm' => $harga_tebus['harga'], 'bakiupah' => $upah_tebus, 'terima' => "*", 'kodgl' => "0", @@ -557,6 +560,7 @@ class TebusController extends Controller 'margin_semasa' => ($request->jeniskeuntungan == 'onepercent') ? $margin_semasa : 0, 'tempoh' => $gadai['tempoh'], 'beza_tempoh' => ($gadai['tempoh'] - $gadai['tempohbayar']), + 'rounded' => $harga_tebus['rounded'], ]); if($request->jenistebus == 'P'){ @@ -579,7 +583,7 @@ class TebusController extends Controller 'nokp' => $gadai['nokp'], 'teller' => $request->teller, 'kodcaw' => $kodcaw, - 'duit_masuk' => $harga_tebus, + 'duit_masuk' => $harga_tebus['harga'], 'created_at' => $current, 'bakiharga' => $baki_hargajualan, 'nowakil' => (int)$request->nowakil, diff --git a/app/Services/Reports/OnePercentService.php b/app/Services/Reports/OnePercentService.php index 770be63..6dede56 100644 --- a/app/Services/Reports/OnePercentService.php +++ b/app/Services/Reports/OnePercentService.php @@ -4,6 +4,7 @@ namespace App\Services\Reports; use App\Cawangan; use App\CawanganDetail; +use App\Gadai; use App\TransaksiKeuntungan; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; @@ -13,18 +14,49 @@ class OnePercentService { // `B` stands for balance sheet and `L` stands for Ledger + private $kod_cawangan; + private $cawangan; + public function __construct($kod_cawangan){ + $this->kod_cawangan = $kod_cawangan; + $this->cawangan = Cawangan::where('kodcaw',$kod_cawangan)->first(); + } - public function __construct($kod_cawangan) - { + + public function getTotalRounded($type='B',$start = '2023-12-14',$end = '2023-12-14'){ + if($type == 'B'){ + $rounded = TransaksiKeuntungan::on('mysql7') + ->leftJoin('transaction as trans', function($join) + { + $join->on('trans.norujukan', '=', 'transaksi_keuntungan.norujukan'); + $join->on('trans.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran'); + }) + ->where('trans.trans_type','T') + ->sum('transaksi_keuntungan.rounded'); + + }else if($type == 'L'){ + $rounded = TransaksiKeuntungan::on('mysql7') + ->whereDate('tarikh_bayaran','>=',$start) + ->whereDate('tarikh_bayaran','<=',$end) + ->sum('rounded');; + } + + return $rounded; } - public function getTotalKeuntungan($type = 'B',$start = '2023-12-14',$end = '2023-12-14') : Float{ - + public function getTotalKeuntungan($type = 'B',$start = '2023-12-14',$end = '2023-12-14') : Float{ if($type == 'B'){ - $keuntungan = TransaksiKeuntungan::on('mysql7')->sum('onepercent_rebet'); - }else if($type == 'L'){ + $norujukan = Gadai::on($this->cawangan['mysql'])->where('sttebus','T')->where('tagbaru',1)->pluck('norujukan'); + $keuntungan = TransaksiKeuntungan::on('mysql7') + ->whereIn('norujukan',$norujukan) + ->sum('onepercent_rebet'); + + }else if($type == 'L'){ + $norujukan = Gadai::on($this->cawangan['mysql'])->where('sttebus','T')->where('tagbaru',1)->where('t_update','>=',$start)->where('t_update','<=',$end)->pluck('norujukan'); + + $keuntungan = TransaksiKeuntungan::on('mysql7') + ->whereIn('norujukan',$norujukan) ->whereDate('tarikh_bayaran','>=',$start) ->whereDate('tarikh_bayaran','<=',$end) ->sum('onepercent_rebet');; @@ -37,12 +69,16 @@ class OnePercentService if($type == 'B'){ - $ujrah = TransaksiKeuntungan::on('mysql7')->sum('ujrah_rebet'); - // $ujrah = TransaksiKeuntungan::on('mysql7')->selectRaw('SUM(ujrah - ujrah_rebet) as total') - // ->first(); - // $ujrah = $ujrah['total']; - }else if($type == 'L'){ + $norujukan = Gadai::on($this->cawangan['mysql'])->where('sttebus','T')->where('tagbaru',1)->pluck('norujukan'); + $ujrah = TransaksiKeuntungan::on('mysql7') + ->whereIn('norujukan',$norujukan) + ->sum('ujrah_rebet'); + }else if($type == 'L'){ + $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');; diff --git a/app/Services/TawarruqServices.php b/app/Services/TawarruqServices.php new file mode 100644 index 0000000..1905df4 --- /dev/null +++ b/app/Services/TawarruqServices.php @@ -0,0 +1,16 @@ +getActiveDB(); foreach($db_connection as $dbase){ - Schema::connection($dbase)->table('gadai', function (Blueprint $table) { - $table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru']); - }); + if (Schema::connection('mysql7')->hasColumn('ujrah', 'onepercent')){ + Schema::connection($dbase)->table('gadai', function (Blueprint $table) { + $table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru']); + }); + } } } } diff --git a/database/migrations/2023_11_11_101144_add_onepercent_to_transaction_keuntungan_table.php b/database/migrations/2023_11_11_101144_add_onepercent_to_transaction_keuntungan_table.php index 59d4036..e036226 100644 --- a/database/migrations/2023_11_11_101144_add_onepercent_to_transaction_keuntungan_table.php +++ b/database/migrations/2023_11_11_101144_add_onepercent_to_transaction_keuntungan_table.php @@ -21,6 +21,7 @@ class AddOnepercentToTransactionKeuntunganTable extends Migration $table->decimal('tempoh', 5, 2); $table->decimal('beza_tempoh', 5, 2); $table->decimal('margin_semasa', 5, 2); + $table->decimal('rounded', 5, 2); }); } @@ -31,8 +32,10 @@ class AddOnepercentToTransactionKeuntunganTable extends Migration */ public function down() { - Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) { - $table->dropColumn(['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa']); - }); + if (Schema::connection('mysql7')->hasColumn('ujrah', 'onepercent')){ + Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) { + $table->dropColumn(['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa','rounded']); + }); + } } } diff --git a/database/migrations/2023_11_11_104203_add_onepercent_to_tebus_table.php b/database/migrations/2023_11_11_104203_add_onepercent_to_tebus_table.php index 8b09cc0..d09b7ea 100644 --- a/database/migrations/2023_11_11_104203_add_onepercent_to_tebus_table.php +++ b/database/migrations/2023_11_11_104203_add_onepercent_to_tebus_table.php @@ -57,9 +57,11 @@ class AddOnepercentToTebusTable extends Migration $db_connection = $this->getActiveDB(); foreach($db_connection as $dbase){ - Schema::connection($dbase)->table('tebus', function (Blueprint $table) { - $table->dropColumn(['ujrah', 'onepercent']); - }); + if (Schema::connection($dbase)->hasColumn('ujrah', 'onepercent')){ + Schema::connection($dbase)->table('tebus', function (Blueprint $table) { + $table->dropColumn(['ujrah', 'onepercent']); + }); + } } } } diff --git a/database/migrations/2023_11_14_121109_add_columns_to_komuditi_transaksi.php b/database/migrations/2023_11_14_121109_add_columns_to_komuditi_transaksi.php index 1c61cb9..baac714 100644 --- a/database/migrations/2023_11_14_121109_add_columns_to_komuditi_transaksi.php +++ b/database/migrations/2023_11_14_121109_add_columns_to_komuditi_transaksi.php @@ -42,7 +42,7 @@ class AddColumnsToKomuditiTransaksi extends Migration { $online_arrahn_connection_array = array_filter(config('database.connections'), function($connection) { - if($connection['database'] === 'online_arrahn' || $connection['database'] === 'master_krk'){ + if($connection['database'] === 'online_arrahn2' || $connection['database'] === 'master_krk'){ return true; } diff --git a/routes/report.php b/routes/report.php index c4cdbbd..2ceea39 100644 --- a/routes/report.php +++ b/routes/report.php @@ -12,6 +12,9 @@ $router->group(['prefix'=>'api/reports'], function () use ($router){ $router->get('onepercent/ledger/{kod_cawangan}', ['uses' => 'OnePercentController@getKeuntunganLejerAm']); $router->get('ujrah/balance/{kod_cawangan}', ['uses' => 'OnePercentController@getUjrahImbangDuga']); $router->get('ujrah/ledger/{kod_cawangan}', ['uses' => 'OnePercentController@getUjrahLejerAm']); + $router->get('rounded/balance/{kod_cawangan}', ['uses' => 'OnePercentController@getRoundedImbangDuga']); + $router->get('rounded/ledger/{kod_cawangan}', ['uses' => 'OnePercentController@getRoundedLejerAm']); + $router->get('totalrebate', ['uses' => 'OnePercentController@getTotalRebate']); }); });