Merged in test-simulator-nisha (pull request #155)
Test simulator nisha
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\PayableUjrahBranch;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PayableUjrahBranchController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$payableUjrahBranch = PayableUjrahBranch::with('cawangan_information')->get()->toJson();
|
||||
|
||||
return json_encode($payableUjrahBranch);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated_data = $request->validate([
|
||||
'details_caw' => 'required',
|
||||
'kodcaw' => 'required',
|
||||
]);
|
||||
|
||||
$created_branch = PayableUjrahBranch::create($validated_data);
|
||||
|
||||
return response(json_encode($created_branch), 200);
|
||||
}
|
||||
|
||||
public function syncStatus(Request $request)
|
||||
{
|
||||
|
||||
$getDetailCawanganFromKodCaw = function($kodcaw){
|
||||
$cawangan_details = Cawangan::all(['kodcaw', 'details_caw']);
|
||||
return $cawangan_details->where('kodcaw', $kodcaw)->first()->details_caw;
|
||||
};
|
||||
|
||||
// payable ujrah updates
|
||||
$previous_payable_ujrah_branch = PayableUjrahBranch::select('kodcaw as branch', 'gadaian_ujrah_payable')->get();
|
||||
|
||||
$payable_ujrah_branch = collect($request->gadai_ujrah_payable_branches);
|
||||
|
||||
$payable_ujrah_branch_updates = $this->findDiff($previous_payable_ujrah_branch, $payable_ujrah_branch, 'branch');
|
||||
|
||||
$payable_ujrah_branch_updates->each(function ($item, $key) {
|
||||
PayableUjrahBranch::where('kodcaw', $key)->update(['gadaian_ujrah_payable' => $item['gadaian_ujrah_payable']]);
|
||||
});
|
||||
|
||||
$generateUpdateMessagePayableUjrahBranch = function($updateData) use($getDetailCawanganFromKodCaw){
|
||||
|
||||
return $updateData->map(function($item, $index) use($getDetailCawanganFromKodCaw) {
|
||||
$cawanganName = $getDetailCawanganFromKodCaw($index);
|
||||
|
||||
$gadaian_ujrah_payable_note = $item['gadaian_ujrah_payable'] === 0 ? 'gadaian ujrah payment disabled' : 'gadaian ujrah payment enabled';
|
||||
|
||||
return "$cawanganName $gadaian_ujrah_payable_note";
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
// tawarruq version updates
|
||||
$previous_branch_tawarruq_version = Cawangan::select('kodcaw as branch', 'version as tawarruq_version')->get();
|
||||
|
||||
$branch_tawarruq_version = collect($request->branch_tawarruq_version);
|
||||
|
||||
$arrahn_master_db_updates = $this->findDiff($previous_branch_tawarruq_version, $branch_tawarruq_version, 'branch');
|
||||
|
||||
$arrahn_master_db_updates->each(function ($item, $key) {
|
||||
Cawangan::where('kodcaw', $key)->update(['version' => $item['tawarruq_version']]);
|
||||
});
|
||||
|
||||
$generateUpdateMessageTawarruqVersion = function($updateData) use($getDetailCawanganFromKodCaw){
|
||||
|
||||
return $updateData->map(function($item, $index) use($getDetailCawanganFromKodCaw) {
|
||||
$cawanganName = $getDetailCawanganFromKodCaw($index);
|
||||
|
||||
$tawarruq_version = $item['tawarruq_version'];
|
||||
return "$cawanganName change to use tawarruq version : $tawarruq_version";
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'updates_done' => [
|
||||
'updated_branch_tawarruq_version' => $generateUpdateMessageTawarruqVersion($arrahn_master_db_updates),
|
||||
'updated_payable_ujrah' => $generateUpdateMessagePayableUjrahBranch($payable_ujrah_branch_updates),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
}
|
||||
|
||||
// SUPPORTING METHODS
|
||||
public function findDiff(Collection $collectionA, Collection $collectionB, $compare_key = 'id')
|
||||
{
|
||||
// Filter and find differences
|
||||
$differences = $collectionA->mapWithKeys(function ($itemA) use ($collectionB, $compare_key) {
|
||||
$itemB = $collectionB->firstWhere($compare_key, $itemA[$compare_key]);
|
||||
|
||||
if ($itemB) {
|
||||
$diff = collect($itemB)->diffAssoc($itemA);
|
||||
if ($diff->isNotEmpty()) {
|
||||
return [$itemA[$compare_key] => $diff];
|
||||
}
|
||||
} else {
|
||||
return [$itemA[$compare_key] => collect($itemA)];
|
||||
}
|
||||
|
||||
return [];
|
||||
})->filter();
|
||||
|
||||
return $differences;
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,12 @@ use Carbon\Carbon;
|
||||
use App\Services\OnePercentServices;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Support\v2\GadaiV2 as Version2Gadai;
|
||||
use App\Support\v2\Calculation;
|
||||
|
||||
use App\Http\Controllers\TebusController as TebusController;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class TransactionOnlineController extends Controller
|
||||
{
|
||||
@@ -80,12 +84,12 @@ class TransactionOnlineController extends Controller
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])->where([['norujukan',$transaction['norujukan']],['nokp',$transaction['nokp']]])->first();
|
||||
if($transaction->jenisbayaran == 'A'){
|
||||
if($gadai_data['hargajualan'] > 0){
|
||||
$this->updateGadaiMarhunKaunter($transaction['kodcaw'],$transaction['norujukan'],$transaction['total_payment'],$transaction['paid_at'],$transaction['tempohbayar']);
|
||||
$response = $this->updateGadaiMarhunOnline($transaction['kodcaw'],$transaction['norujukan'],$transaction['total_payment'],$transaction['paid_at'],$transaction['tempohbayar']);
|
||||
}else{
|
||||
$this->createAdvansur($transaction['kodcaw'],$transaction['norujukan'],$transaction['total_payment'],$transaction['paid_at']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GlDetail::on($cawangan['mysql'])->create([
|
||||
'kodcaw' => $transaction['kodcaw'],
|
||||
@@ -151,7 +155,140 @@ class TransactionOnlineController extends Controller
|
||||
return $upah_rebet;
|
||||
}
|
||||
|
||||
public function updateGadaiMarhunKaunter($kodcaw,$norujukan,$bayaran,$paid_at,$tempohbayar){
|
||||
// public function updateGadaiMarhunKaunter($kodcaw,$norujukan,$bayaran,$paid_at,$tempohbayar){
|
||||
// $current = Carbon::now();
|
||||
// $current = new Carbon();
|
||||
|
||||
// $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
// $gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
|
||||
// if($tempohbayar == 0.0){
|
||||
// $tempohbayar = $gadai['tempoh'];
|
||||
// }
|
||||
|
||||
// $upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar);
|
||||
// $upahrebet = $this->kiraUpahRebet($kodcaw,$norujukan,$tempohbayar);
|
||||
|
||||
// $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;
|
||||
// }
|
||||
// $onepercent = new OnePercentServices();
|
||||
|
||||
// $old_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
// $margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||
// $keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||
// $ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']);
|
||||
|
||||
// if($gadai['tagbaru'] == 1){
|
||||
// $upah_semasa = $keuntungan;
|
||||
// }
|
||||
|
||||
// $baki_hargajualan = $gadai['bakihargajualan'] - $bayaran;
|
||||
|
||||
// $baki_bayaran = $bayaran - $upahsemasa;
|
||||
// //$baki_bayaran = $bayaran - $upah_semasa;
|
||||
|
||||
// $baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran;
|
||||
|
||||
// $margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||
|
||||
// $keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||
// $ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']);
|
||||
|
||||
// $onepercentasal = $gadai['pinjaman'] * (1/100);
|
||||
|
||||
// try {
|
||||
|
||||
// DB::connection('mysql7')->transaction(function () use($onepercentasal,$ujrahasal,$keuntungan,$norujukan,$gadai,$kodcaw,$current,$baki_hargajualan,$upahsemasa,$baki_bayaran,$upahrebet,$cawangan,$old_data,$baki_pinjaman,$lelong_tawarruq,$margin_semasa,$bayaran,$upah_semasa) {
|
||||
|
||||
// $transaction = Transaction::on('mysql7')->create([
|
||||
// 'trans_type' => 'A',
|
||||
// 'norujukan' => $norujukan,
|
||||
// 'nokp' => $gadai['nokp'],
|
||||
// 'teller' => 'Online',
|
||||
// 'kodcaw' => $kodcaw,
|
||||
// 'duit_masuk' => $bayaran,
|
||||
// 'created_at' => $current,
|
||||
// 'bakiharga' => $baki_hargajualan,
|
||||
// ]);
|
||||
|
||||
// if($gadai['tempoh'] >= 12.0){
|
||||
// $tempoh = 12;
|
||||
// }else{
|
||||
// $tempoh = $gadai['tempoh'];
|
||||
// }
|
||||
// $bilang_bln = $tempoh - $gadai['tempohbayar'];
|
||||
|
||||
|
||||
|
||||
// $transaction_upah = TransaksiKeuntungan::on('mysql7')->create([
|
||||
// 'norujukan' => $norujukan,
|
||||
// 'bayaran_keuntungan' => $upahsemasa,
|
||||
// 'bayaran_pembiayaan' => $baki_bayaran,
|
||||
// 'keuntungan_rebet'=> $upahrebet,
|
||||
// 'tarikh_bayaran'=> $current,
|
||||
// 'kodcaw'=> $kodcaw,
|
||||
// 'ujrah' => ($keuntungan['ujrah'] * $bilang_bln),
|
||||
// 'ujrah_rebet' => ($ujrahasal*$bilang_bln),
|
||||
// 'onepercent' => ($onepercentasal * $bilang_bln),
|
||||
// 'onepercent_rebet' => ($keuntungan['onepercent'] * $bilang_bln),
|
||||
// 'tempoh' => $gadai['tempoh'],
|
||||
// 'beza_tempoh' => $bilang_bln,
|
||||
// 'margin_semasa' => $margin_semasa,
|
||||
// ]);
|
||||
//
|
||||
|
||||
|
||||
// DB::connection($cawangan['mysql'])->transaction(function () use($cawangan,$baki_pinjaman,$current,$norujukan,$gadai,$baki_hargajualan,$lelong_tawarruq,$margin_semasa){
|
||||
|
||||
// $margin_updated = ($baki_pinjaman / $gadai['nilaimarhun']) * 100;
|
||||
|
||||
// $update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->update(array(
|
||||
// 'bakipjm' => $baki_pinjaman,
|
||||
// 'jbg' => 0,
|
||||
// 't_update' => $current->toDateString(),
|
||||
// 'bakihargajualan' => $baki_hargajualan,
|
||||
// 'tempohbayar' => $gadai['tempoh'],
|
||||
// 'lelong_tawarruq' => $lelong_tawarruq,
|
||||
// 'margin_semasa' => $margin_updated,
|
||||
// ));
|
||||
// });
|
||||
|
||||
// $new_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
|
||||
// $audit = new Audit();
|
||||
// $audit->users = 'Online';
|
||||
// $audit->actions = 'Bayaran Ansuran';
|
||||
// $audit->norujukan = $norujukan;
|
||||
// $audit->new_data = $new_data;
|
||||
// $audit->old_data = $old_data;
|
||||
// $audit->kodcaw = $kodcaw;
|
||||
// $audit->created_at = $current;
|
||||
// $audit->updated_at = $current;
|
||||
// $audit->save();
|
||||
|
||||
// if(!$transaction || !$transaction_upah) {
|
||||
// throw new \Exception('One of the database operations failed.');
|
||||
// }
|
||||
|
||||
// DB::commit();
|
||||
|
||||
// });
|
||||
// }catch(\Exception $e){
|
||||
// Log::error("Transaction failed: " . $e->getMessage());
|
||||
// return response()->json("Transaction failed: " . $e->getMessage(),500);
|
||||
// }
|
||||
|
||||
// return response()->json("success",200);
|
||||
// }
|
||||
|
||||
public function updateGadaiMarhunOnline($kodcaw,$norujukan,$bayaran,$paid_at,$tempohbayar){
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
@@ -162,8 +299,7 @@ class TransactionOnlineController extends Controller
|
||||
$tempohbayar = $gadai['tempoh'];
|
||||
}
|
||||
|
||||
$upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar);
|
||||
$upahrebet = $this->kiraUpahRebet($kodcaw,$norujukan,$tempohbayar);
|
||||
$upahrebet = $this->kiraUpahRebet($kodcaw,$norujukan,$tempohbayar);
|
||||
|
||||
$total_bayaran_prev = Transaction::on('mysql7')->where([['norujukan','=',$norujukan],['trans_type','=','A']])->sum('duit_masuk');
|
||||
|
||||
@@ -178,29 +314,14 @@ class TransactionOnlineController extends Controller
|
||||
|
||||
$old_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
$margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||
$keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||
$ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']);
|
||||
|
||||
if($gadai['tagbaru'] == 1){
|
||||
$upah_semasa = $keuntungan;
|
||||
}
|
||||
|
||||
$baki_hargajualan = $gadai['bakihargajualan'] - $bayaran;
|
||||
|
||||
$baki_bayaran = $bayaran - $upahsemasa;
|
||||
|
||||
$baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran;
|
||||
|
||||
$margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||
|
||||
$keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||
$ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']);
|
||||
|
||||
$onepercentasal = $gadai['pinjaman'] * (1/100);
|
||||
|
||||
try {
|
||||
|
||||
DB::connection('mysql7')->transaction(function () use($onepercentasal,$ujrahasal,$keuntungan,$norujukan,$gadai,$kodcaw,$current,$baki_hargajualan,$upahsemasa,$baki_bayaran,$upahrebet,$cawangan,$old_data,$baki_pinjaman,$lelong_tawarruq,$margin_semasa,$bayaran) {
|
||||
DB::connection('mysql7')->transaction(function () use($norujukan,$gadai,$kodcaw,$current,$baki_hargajualan,$cawangan,$old_data,$lelong_tawarruq,$margin_semasa,$bayaran,$tempohbayar) {
|
||||
|
||||
$transaction = Transaction::on('mysql7')->create([
|
||||
'trans_type' => 'A',
|
||||
@@ -220,22 +341,65 @@ class TransactionOnlineController extends Controller
|
||||
}
|
||||
$bilang_bln = $tempoh - $gadai['tempohbayar'];
|
||||
|
||||
$transaction_upah = TransaksiKeuntungan::on('mysql7')->create([
|
||||
'norujukan' => $norujukan,
|
||||
'bayaran_keuntungan' => $upahsemasa,
|
||||
'bayaran_pembiayaan' => $baki_bayaran,
|
||||
'keuntungan_rebet'=> $upahrebet,
|
||||
'tarikh_bayaran'=> $current,
|
||||
'kodcaw'=> $kodcaw,
|
||||
'ujrah' => ($keuntungan['ujrah'] * $bilang_bln),
|
||||
'ujrah_rebet' => ($ujrahasal*$bilang_bln),
|
||||
'onepercent' => ($onepercentasal * $bilang_bln),
|
||||
'onepercent_rebet' => ($keuntungan['onepercent'] * $bilang_bln),
|
||||
'tempoh' => $gadai['tempoh'],
|
||||
'beza_tempoh' => $bilang_bln,
|
||||
'margin_semasa' => $margin_semasa,
|
||||
]);
|
||||
if($gadai['tagbaru'] == 0){
|
||||
$upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar);
|
||||
$baki_bayaran = $bayaran - $upahsemasa;
|
||||
$upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar);
|
||||
$upahrebet = $this->kiraUpahRebet($kodcaw,$norujukan,$tempohbayar);
|
||||
$transaction_upah = TransaksiKeuntungan::on('mysql7')->create([
|
||||
'norujukan' => $norujukan,
|
||||
'bayaran_keuntungan' => $upahsemasa,
|
||||
'bayaran_pembiayaan' => $baki_bayaran,
|
||||
'keuntungan_rebet'=> $upahrebet,
|
||||
'tarikh_bayaran'=> $current,
|
||||
'kodcaw'=> $kodcaw,
|
||||
'ujrah' => 0,
|
||||
'ujrah_rebet' => 0,
|
||||
'onepercent' => 0,
|
||||
'onepercent_rebet' => 0,
|
||||
'tempoh' => $gadai['tempoh'],
|
||||
'beza_tempoh' => $bilang_bln,
|
||||
'margin_semasa' => $margin_semasa,
|
||||
]);
|
||||
} else {
|
||||
|
||||
$onepercent = new OnePercentServices();
|
||||
$keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||
$ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['percentpinj']);
|
||||
$onepercentasal = $gadai['pinjaman'] * (1/100);
|
||||
|
||||
$gadaionepercent = new Version2Gadai($kodcaw,$cawangan);
|
||||
|
||||
$upahsemasa = $gadaionepercent->kiraupahOnePercent($norujukan);
|
||||
$upahrebet = $gadaionepercent->kiraUpahRebet($norujukan);
|
||||
$baki_bayaran = $bayaran - $upahsemasa;
|
||||
|
||||
$ujrah_calculation = $this->getUjrah($kodcaw, $norujukan);
|
||||
|
||||
$onepercent = new Calculation();
|
||||
$ujrah = $onepercent->getRoundedMethod($ujrahasal * $bilang_bln);
|
||||
$ujrah_rebate = $onepercent->getRoundedMethod($ujrah_calculation['ujrah_sebenar'] - $ujrah_calculation['ujrah_rebet']);
|
||||
$keun = $onepercent->getRoundedMethod($onepercentasal * $bilang_bln);
|
||||
$keuntungan_rebate = $onepercent->getRoundedMethod($keuntungan['onepercent'] * $bilang_bln);
|
||||
|
||||
$transaction_upah = TransaksiKeuntungan::on('mysql7')->create([
|
||||
'norujukan' => $norujukan,
|
||||
'bayaran_keuntungan' => $upahsemasa,
|
||||
'bayaran_pembiayaan' => $baki_bayaran,
|
||||
'keuntungan_rebet'=> $upahrebet,
|
||||
'tarikh_bayaran'=> $current,
|
||||
'kodcaw'=> $kodcaw,
|
||||
'ujrah' => $ujrah,
|
||||
'ujrah_rebet' => $ujrah_rebate,
|
||||
'onepercent' => $keun,
|
||||
'onepercent_rebet' => $keuntungan_rebate,
|
||||
'tempoh' => $gadai['tempoh'],
|
||||
'beza_tempoh' => $bilang_bln,
|
||||
'margin_semasa' => $margin_semasa,
|
||||
]);
|
||||
}
|
||||
|
||||
$baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran;
|
||||
DB::connection($cawangan['mysql'])->transaction(function () use($cawangan,$baki_pinjaman,$current,$norujukan,$gadai,$baki_hargajualan,$lelong_tawarruq,$margin_semasa){
|
||||
|
||||
$margin_updated = ($baki_pinjaman / $gadai['nilaimarhun']) * 100;
|
||||
@@ -268,6 +432,7 @@ class TransactionOnlineController extends Controller
|
||||
throw new \Exception('One of the database operations failed.');
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
});
|
||||
@@ -276,7 +441,8 @@ class TransactionOnlineController extends Controller
|
||||
return response()->json("Transaction failed: " . $e->getMessage(),500);
|
||||
}
|
||||
|
||||
return response()->json("success",200);
|
||||
return response()->json("success",200);
|
||||
|
||||
}
|
||||
|
||||
public function createAdvansur($kodcaw,$norujukan,$bayaran,$paid_at){
|
||||
@@ -322,7 +488,7 @@ class TransactionOnlineController extends Controller
|
||||
$current = new Carbon();
|
||||
$boolmasa = false;
|
||||
$transaction_online = TransactionOnline::on('mysql7')->where([['norujukan',$request->norujukan],['status','PAID'],['update_status',0],['tarikh',$current->toDateString()]])->first();
|
||||
|
||||
|
||||
$transaction_masa = TransactionOnline::on('mysql7')->where([['norujukan',$request->norujukan],['status','NOT PAID'],['tarikh',$current->toDateString()]])
|
||||
->orderBy('masa', 'desc')->first();
|
||||
|
||||
@@ -332,7 +498,7 @@ class TransactionOnlineController extends Controller
|
||||
$carbonmasaexpired->addMinutes(10);
|
||||
|
||||
$boolmasa = ($carbonmasaexpired->greaterThanOrEqualTo($current) && $carbonmasa->lessThanOrEqualTo($current)) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
if($transaction_online || $boolmasa){
|
||||
return response()->json(true);
|
||||
@@ -355,7 +521,7 @@ class TransactionOnlineController extends Controller
|
||||
|
||||
return response()->json($transaction,200);
|
||||
}
|
||||
|
||||
|
||||
public function CustomerInfo(Request $request){
|
||||
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
@@ -368,17 +534,28 @@ class TransactionOnlineController extends Controller
|
||||
->where([['sttebus','=',''],['taglel',0],['nokp','=',$request->ic]])
|
||||
->orderBy('t_gadai','desc')
|
||||
->get()->toArray();
|
||||
//dd($gadai, $cawangan);
|
||||
if(sizeof($gadai) != 0){
|
||||
foreach($gadai as $gad)
|
||||
{
|
||||
|
||||
if($gad['tagbaru'] == 1){
|
||||
$jenis = 'onepercent';
|
||||
}else{
|
||||
$jenis = 'asal';
|
||||
}
|
||||
$result = (new TebusController)->kiraupahTawarruq($gad['kodcaw'],$gad['norujukan'],$jenis);
|
||||
|
||||
$gad['keuntungan'] = $result;
|
||||
$array_utg = new \Illuminate\Http\Request([
|
||||
'jeniskeuntungan' => $jenis
|
||||
]);
|
||||
|
||||
$result = (new TebusController)->upahTawarruq($gad['kodcaw'],$gad['norujukan'],$array_utg);
|
||||
|
||||
if($jenis == 'onepercent') {
|
||||
$gad['keuntungan'] = $result['pendapatan'];
|
||||
} else {
|
||||
$gad['keuntungan'] = $result;
|
||||
}
|
||||
array_push($gadai_all,$gad);
|
||||
}
|
||||
}
|
||||
@@ -398,7 +575,7 @@ class TransactionOnlineController extends Controller
|
||||
if(sizeof($akanlelong) != 0){
|
||||
foreach($akanlelong as $lelong)
|
||||
{
|
||||
$result = (new TebusController)->kiraupahTawarruq($lelong['kodcaw'],$lelong['norujukan']);
|
||||
$result = (new TebusController)->kiraupahTawarruq($lelong['kodcaw'],$lelong['norujukan'],$array_utg);
|
||||
$lelong['keuntungan'] = $result;
|
||||
array_push($akanlelongarray,$lelong);
|
||||
}
|
||||
@@ -411,7 +588,7 @@ class TransactionOnlineController extends Controller
|
||||
'lelong' => $akanlelongarray
|
||||
),200);
|
||||
}
|
||||
|
||||
|
||||
public function updateTagPortal(Request $request){
|
||||
$transaction = TransactionOnline::on('mysql7')->where('billplz_id','=',$request->billplz_id)->update(array(
|
||||
'tagportal' => 1
|
||||
@@ -420,4 +597,37 @@ class TransactionOnlineController extends Controller
|
||||
return response()->json($transaction,200);
|
||||
}
|
||||
|
||||
public function getUjrah($kodcaw, $norujukan)
|
||||
{
|
||||
|
||||
try {
|
||||
$base_url = config('app.url');
|
||||
|
||||
$gadai = Http::get($base_url . "/api/gadai/norujukan/$kodcaw/$norujukan")->json()[0];
|
||||
$jenis_keuntungan = $gadai['tagbaru'] === 1 ? 'onepercent' : 'asal';
|
||||
|
||||
|
||||
$upah_tawarruq = Http::get($base_url . "/api/upahtawarruq/$kodcaw/$norujukan", ['jeniskeuntungan' => $jenis_keuntungan])->json();
|
||||
$upah_rebet_tawarruq = Http::get($base_url . "/api/upahrebettawarruq/$kodcaw/$norujukan", ['jeniskeuntungan' => $jenis_keuntungan])->json();
|
||||
|
||||
if($jenis_keuntungan === 'onepercent'){
|
||||
$ujrah_sebenar = (float)$upah_tawarruq['ujrah'];
|
||||
$ujrah_rebet = $ujrah_sebenar - (float)$upah_rebet_tawarruq['ujrah'];
|
||||
|
||||
return [
|
||||
'ujrah_sebenar' => $ujrah_sebenar,
|
||||
'ujrah_rebet' => $ujrah_rebet,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ujrah_sebenar' => (float)$upah_tawarruq,
|
||||
'ujrah_rebet' => (float)$upah_rebet_tawarruq,
|
||||
];
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user