diff --git a/app/Http/Controllers/GadaiController.php b/app/Http/Controllers/GadaiController.php index b3db0a6..905ec31 100644 --- a/app/Http/Controllers/GadaiController.php +++ b/app/Http/Controllers/GadaiController.php @@ -2268,6 +2268,15 @@ class GadaiController extends Controller case 'WB': $tarikhtawarruq = '2021-05-24'; break; + case 'APM': + $tarikhtawarruq = '2021-06-08'; + break; + case 'ARM': + $tarikhtawarruq = '2021-06-08'; + break; + case '020306': + $tarikhtawarruq = '2021-06-08'; + break; } $rekod_emaspalsu = Gadai::on($cawangan['mysql']) diff --git a/app/Http/Controllers/GlejerController.php b/app/Http/Controllers/GlejerController.php index 9879e2d..add1b48 100644 --- a/app/Http/Controllers/GlejerController.php +++ b/app/Http/Controllers/GlejerController.php @@ -37,14 +37,11 @@ class GlejerController extends Controller public function Getglejer_Data($tarikh1,$tarikh2,$kodcaw) { - - - - $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); - $glejer=Glejer::on($cawangan['mysql'])->whereBetween('tarikh',[$tarikh1,$tarikh2])->orderBy('glcode','ASC')->get(); - return response()->json($glejer); - + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + $db=$cawangan['mysql']; + $glejer=DB::connection($db)->select("SELECT glcode, descpt , SUM(debit)AS total_debit, SUM(kredit) AS total_kredit, SUM(hariini) AS totalharini FROM glejer where tarikh BETWEEN '".$tarikh1."' and '".$tarikh2."' GROUP BY glcode,descpt ORDER BY glcode asc"); + return response()->json($glejer); } diff --git a/app/Http/Controllers/LelongController.php b/app/Http/Controllers/LelongController.php index ceacbb1..5230f2f 100644 --- a/app/Http/Controllers/LelongController.php +++ b/app/Http/Controllers/LelongController.php @@ -182,11 +182,6 @@ class LelongController extends Controller ->where('baki','>=',0) ->sum('baki'); } - - - - - // dd($bakilelong->toSql()); $ansrugi = AnsRugi::on($cawangan['mysql']) ->sum('bayaran'); diff --git a/app/Http/Controllers/PortalBillplzController.php b/app/Http/Controllers/PortalBillplzController.php new file mode 100644 index 0000000..7dc1f67 --- /dev/null +++ b/app/Http/Controllers/PortalBillplzController.php @@ -0,0 +1,15 @@ +select('collection_id')->where('kodcaw',$request->kodcaw)->first(); + + return response()->json($collection_id['collection_id']); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/TacExpressPaymentController.php b/app/Http/Controllers/TacExpressPaymentController.php new file mode 100644 index 0000000..5e5cf7d --- /dev/null +++ b/app/Http/Controllers/TacExpressPaymentController.php @@ -0,0 +1,61 @@ +addMinutes(15); + + TacExpressPayment::on('mysql7')->create([ + 'norujukan' => $request->norujukan, + 'tac_no' => $request->otp_token, + 'expired_at' => $expired_at + ]); + + $mobileno = '6'.$request->mobileno; + // $mobileno = '60189025461'; + $messages = 'SPARE : SMS-OTP '. $request->otp_token . ' for one time usage on ' . $expired_at . '. Call AR-RAHN CARELINE CENTRE 1300-22-4343 if not request'; + + $status = Http::get('http://gateway.onewaysms.com.au:10001/api.aspx',[ + 'apiusername' => 'APIQ4LP5EMKXM', + 'apipassword' => 'APIQ4LP5EMKXM7CQOX', + 'senderid' => 'INFO', + 'mobileno' => $mobileno, + 'message'=> $messages, + 'languagetype'=> 1 + ]); + + return response($status); + } + + public function getTacExpressPayment(Request $request){ + $currentDateTime = Carbon::now(); + $tac_data = TacExpressPayment::on('mysql7')->where([['norujukan',$request->norujukan],['expired_at','>',$currentDateTime]])->get(); + + if(sizeof($tac_data) > 0){ + return response(1); + }else{ + return response(0); + } + } + + public function verifyTacExpressPayment(Request $request){ + $currentDateTime = Carbon::now(); + $tac_data = TacExpressPayment::on('mysql7')->where([['norujukan',$request->norujukan],['tac_no',$request->tac_token],['expired_at','>',$currentDateTime]])->get(); + + if(sizeof($tac_data) > 0){ + return response(1); + }else{ + return response(0); + } + } +} diff --git a/app/Http/Controllers/TebusController.php b/app/Http/Controllers/TebusController.php index 971aceb..44e966b 100644 --- a/app/Http/Controllers/TebusController.php +++ b/app/Http/Controllers/TebusController.php @@ -1023,7 +1023,7 @@ class TebusController extends Controller $keuntungan = TransaksiKeuntungan::on('mysql7') ->join($cawangan['db_name'].'.gadai as db2','transaksi_keuntungan.norujukan','=','db2.norujukan') ->whereDate('transaksi_keuntungan.tarikh_bayaran', '<=', $request->tarikh) - ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $dateSM) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<', $dateSM) ->whereYear('tarikh_bayaran','=',$current->year) ->whereNotNull('db2.hargajualan') ->sum('bayaran_keuntungan'); @@ -1031,7 +1031,7 @@ class TebusController extends Controller $keuntunganreducing = TransaksiKeuntungan::on('mysql7') ->join($cawangan['db_name'].'.gadai as db2','transaksi_keuntungan.norujukan','=','db2.norujukan') - ->where('transaksi_keuntungan.tarikh_bayaran' ,'<=', $request->tarikh) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<', $request->tarikh) ->whereDate('transaksi_keuntungan.tarikh_bayaran','>=', $dateSM) ->whereYear('tarikh_bayaran','=',$current->year) ->whereNotNull('db2.hargajualan') @@ -1046,9 +1046,7 @@ class TebusController extends Controller $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); }) ->where('trans.trans_type','!=','A') - // ->where('transaksi_keuntungan.tarikh_bayaran' ,'<=', $daterequest) - // ->where('transaksi_keuntungan.tarikh_bayaran','>=', $dateSM) - ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $request->tarikh) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'=', $request->tarikh) ->whereDate('transaksi_keuntungan.tarikh_bayaran','>=', $dateSM) ->whereYear('tarikh_bayaran','=',$current->year) ->whereNotNull('db2.hargajualan') @@ -1062,21 +1060,13 @@ class TebusController extends Controller $join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at'); }) ->where('trans.trans_type','=','A') - // ->where('transaksi_keuntungan.tarikh_bayaran' ,'<=', $daterequest) - // ->where('transaksi_keuntungan.tarikh_bayaran','>=', $dateSM) - ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'<=', $request->tarikh) + ->whereDate('transaksi_keuntungan.tarikh_bayaran' ,'=', $request->tarikh) ->whereDate('transaksi_keuntungan.tarikh_bayaran','>=', $dateSM) ->whereYear('tarikh_bayaran','=',$current->year) ->whereNotNull('db2.hargajualan') ->sum('bayaran_keuntungan'); - dd($keuntunganreducing,$keuntungan,$bukanansuran,$ansuran); - - // $total = $keuntungan + $keuntunganreducing + ($keuntunganreducinga - $keuntunganansuran); - // dd($total); - // $total = $keuntungan + $keuntunganreducing + $keuntunganansuran; - // $total = $keuntungan + $keuntunganreducing; - + $total = ($keuntungan+$keuntunganreducing + $ansuran + $bukanansuran); return response($total); } diff --git a/app/Http/Controllers/TransactionOnlineController.php b/app/Http/Controllers/TransactionOnlineController.php index a35e189..47fd699 100644 --- a/app/Http/Controllers/TransactionOnlineController.php +++ b/app/Http/Controllers/TransactionOnlineController.php @@ -3,11 +3,22 @@ namespace App\Http\Controllers; use App\TransactionOnline; +use App\Advansur; +use App\Transaction; +use App\TransaksiKeuntungan; +use App\Gadai; +use App\Cawangan; +use App\GlDetail; use Illuminate\Http\Request; use Carbon\Carbon; class TransactionOnlineController extends Controller { + public function getTransactionOnline(Request $request){ + $transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id',$request->billplz_id)->first(); + + return response()->json($transactionOnline); + } public function getLatestNosiri(){ $current = Carbon::now(); $current = new Carbon(); @@ -25,19 +36,185 @@ class TransactionOnlineController extends Controller 'nokp' => $request->nokp, 'reference_no' => $request->reference_no, 'nosiri' => $request->nosiri, + 'billplz_id' => $request->billplz_id, + 'norujukan' => $request->norujukan, + 'kodcaw' => $request->kodcaw, 'total_payment' => $request->total_payment, 'tarikh' => $current->toDateString(), - 'masa' => $current->toTimeString() + 'masa' => $current->toTimeString(), + 'customer_name' => $request->customer_name ]); return response()->json($transaction,201); } - public function updateStatus(){ - $transaction = TransactionOnline::on('mysql7')->where('reference_no','=',$request->reference_no)->update(array( - 'status' => 1 + public function updateStatus(Request $request){ + $transaction = TransactionOnline::on('mysql7')->where('billplz_id','=',$request->billplz_id)->update(array( + 'status' => $request->status, + 'paid_at' => $request->paid_at )); return response()->json($transaction,200); } + + public function updateTransactionOnline(){ + $transactions = TransactionOnline::on('mysql7')->where([['status','PAID'],['update_status',0]])->get(); + $current = Carbon::now(); + $current = new Carbon(); + foreach($transactions as $index=>$transaction){ + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw','=',$transaction['kodcaw']) + ->first(); + $gadai_data = Gadai::on($cawangan['mysql'])->where([['norujukan',$transaction['norujukan']],['nokp',$transaction['nokp']]])->first(); + + if($gadai_data['hargajualan'] > 0){ + $this->updateGadaiMarhunKaunter($transaction['kodcaw'],$transaction['norujukan'],$transaction['total_payment'],$transaction['paid_at']); + }else{ + $this->createAdvansur($transaction['kodcaw'],$transaction['norujukan'],$transaction['total_payment'],$transaction['paid_at']); + } + + GlDetail::on($cawangan['mysql'])->create([ + 'kodcaw' => $transaction['kodcaw'], + 'tarikh' => $current->toDateString(), + 'dtacct' => '1000/010', + 'ktacct' => '1000/020', + 'descpt' => 'SERAHAN BAYAR ONLINE - ' . $transaction['norujukan'], + 'serahan' => $transaction['total_payment'], + 'teller' => 'ONLINE' + ]); + + TransactionOnline::on('mysql7')->where([['norujukan',$transaction['norujukan'],['billplz_id',$transaction['billplz_id']]]])->update([ + 'update_status' => 1, + 'update_serahan' => 1 + ]); + } + + return response()->json('success'); + } + + public function kiraupahTawarruq($kodcaw,$norujukan){ + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw','=',$kodcaw) + ->first(); + + $gadai_data = Gadai::on($cawangan['mysql']) + ->where('norujukan','=',$norujukan) + ->first(); + + $bilang_bln = $gadai_data['tempoh'] - $gadai_data['tempohbayar']; + + $upahsemasa_raw = $bilang_bln * (($gadai_data['kadarupah']/100 )* $gadai_data['pinjaman']); + + $upah_semasa_round = number_format($upahsemasa_raw,2); + $upah_semasa = (float)substr($upah_semasa_round, 0, -1); + + return $upah_semasa; + } + + public function kiraUpahRebet($kodcaw,$norujukan){ + $cawangan = Cawangan::on('mysql7') + ->where('kodcaw','=',$kodcaw) + ->first(); + + $gadai_data = Gadai::on($cawangan['mysql']) + ->where('norujukan','=',$norujukan) + ->first(); + + $bilang_bln = $gadai_data['tempoh'] - $gadai_data['tempohbayar']; + + $upahrebet_raw = $bilang_bln * (($gadai_data['kadarupah']/100 )* $gadai_data['bakipjm']); + + $upah_rebet_round = number_format($upahrebet_raw,2); + $upah_rebet = (float)substr($upah_rebet_round, 0, -1); + + return $upah_rebet; + } + + public function updateGadaiMarhunKaunter($kodcaw,$norujukan,$bayaran,$paid_at){ + $current = Carbon::now(); + $current = new Carbon(); + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first(); + + $upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan); + $upahrebet = $this->kiraUpahRebet($kodcaw,$norujukan); + + $total_bayaran_prev = Transaction::on('mysql7')->where([['norujukan','=',$norujukan],['trans_type','=','A']])->sum('duit_masuk'); + + $total_bayaran_semasa = $total_bayaran_prev + $bayaran; + + if($total_bayaran_semasa >= $gadai['bakiupah']){ + $lelong_tawarruq = 0; + }else{ + $lelong_tawarruq = 1; + } + + $baki_hargajualan = $gadai['bakihargajualan'] - $bayaran; + + $baki_bayaran = $bayaran - $upahsemasa; + + $baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran; + + $transaction = Transaction::on('mysql7')->create([ + 'trans_type' => 'A', + 'norujukan' => $norujukan, + 'nokp' => $gadai['nokp'], + 'teller' => 'Online', + 'kodcaw' => $kodcaw, + 'duit_masuk' => $bayaran, + 'created_at' => Carbon::parse($paid_at), + 'bakiharga' => $baki_hargajualan, + ]); + + $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([ + 'norujukan' => $norujukan, + 'bayaran_keuntungan' => $upahsemasa, + 'bayaran_pembiayaan' => $baki_bayaran, + 'keuntungan_rebet'=> $upahrebet, + 'tarikh_bayaran'=> Carbon::parse($paid_at), + 'kodcaw'=> $kodcaw + ]); + + $update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update(array( + 'bakipjm' => $baki_pinjaman, + 'jbg' => 0, + 't_update' => Carbon::parse($paid_at)->toDateString(), + 'bakihargajualan' => $baki_hargajualan, + 'tempohbayar' => $gadai['tempoh'], + 'lelong_tawarruq' => $lelong_tawarruq + )); + return response()->json($update_gadai, 200); + } + + public function createAdvansur($kodcaw,$norujukan,$bayaran,$paid_at){ + $current = Carbon::now(); + $current = new Carbon(); + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $gadai = Gadai::on($cawangan['mysql'])->where('norujukan',$norujukan)->first(); + + $create_advansur = Advansur::on($cawangan['mysql'])->create([ + 'tarikh'=> Carbon::parse($paid_at)->toDateString(), + 'noresit'=> 0, + 'norujukan' => $norujukan, + 'nopelanggan' => $gadai['nopelanggan'], + 'nilaimarhun' => $gadai['nilaimarhun'], + 'pinjaman' => $gadai['pinjaman'], + 'kadarupah' => $gadai['kadarupah'], + 'glcode' => "1000/010", + 'upahsebenar' => $bayaran, + 'upahDibayar' => $bayaran, + 'teller' => 'Online', + 'prkod' => $gadai['prkod'], + 'jbg' => $gadai['tempoh'], + 'nowakil' => 0, + 'hubungan' => 0, + 'status' => 0, + 'historygadaian' => $norujukan + ]); + + return response()->json($create_advansur ,201); + } } diff --git a/app/Http/Controllers/VaultController.php b/app/Http/Controllers/VaultController.php index d3985ad..eac632c 100644 --- a/app/Http/Controllers/VaultController.php +++ b/app/Http/Controllers/VaultController.php @@ -321,7 +321,7 @@ class VaultController extends Controller //Sebelum Tawarruq - if($kodcaw == 'KB2' || $kodcaw == 'WCY' || $kodcaw == '1STOP') + if($kodcaw == 'KB2' || $kodcaw == 'WCY' || $kodcaw == '1STOP' || $kodcaw == 'ARM' || $kodcaw == 'APM') { $serahanpkb = GlDetail::on($cawangan['mysql']) ->where('dtacct','=',$serahanpkb) diff --git a/app/PortalBillplz.php b/app/PortalBillplz.php new file mode 100644 index 0000000..6c17e1c --- /dev/null +++ b/app/PortalBillplz.php @@ -0,0 +1,26 @@ +group(['prefix'=>'api'], function () use ($router){ $router->get('online/transaction',['uses'=>'TransactionOnlineController@getLatestNosiri']); $router->post('online/transaction',['uses'=>'TransactionOnlineController@create']); $router->put('online/transaction',['uses'=>'TransactionOnlineController@updateStatus']); + $router->get('transaction/online/express',['uses'=>'TransactionOnlineController@getTransactionOnline']); + $router->get('transaction/online/update',['uses'=>'TransactionOnlineController@updateTransactionOnline']); //ANSURAN UPAH API @@ -422,6 +424,14 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('laporan/harian',['uses'=>'LaporanController@laporanHarian']); $router->get('laporan/terkumpul',['uses'=>'LaporanController@laporanTerkumpul']); + + //Collection ID Billplz + $router->get('billplz/collectionid',['uses'=>'PortalBillplzController@getCollectionIDCawangan']); + + //Generate TAC Express Payment + $router->post('tac/generate/express_payment',['uses'=>'TacExpressPaymentController@generateTacExpressPayment']); + $router->get('tac/get/express_payment',['uses'=>'TacExpressPaymentController@getTacExpressPayment']); + $router->get('tac/verify/express_payment',['uses'=>'TacExpressPaymentController@verifyTacExpressPayment']); }); $router->group(['prefix'=>'e-arrahn'], function () use ($router){