Change implementation get ujrah detail
This commit is contained in:
@@ -13,7 +13,7 @@ use App\Audit;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use App\Services\OnePercentServices;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request as HttpRequest;
|
||||
use App\Support\v2\GadaiV2 as Version2Gadai;
|
||||
@@ -24,27 +24,30 @@ use Illuminate\Support\Facades\Http;
|
||||
|
||||
class TransactionOnlineController extends Controller
|
||||
{
|
||||
public function getTransactionOnline(Request $request){
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id',$request->billplz_id)->first();
|
||||
public function getTransactionOnline(Request $request)
|
||||
{
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id', $request->billplz_id)->first();
|
||||
|
||||
return response()->json($transactionOnline);
|
||||
}
|
||||
public function getLatestNosiri(){
|
||||
public function getLatestNosiri()
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$nosiri = TransactionOnline::on('mysql7')->where('tarikh','=',$current->toDateString())->orderBy('nosiri','desc')->first();
|
||||
$nosiri = TransactionOnline::on('mysql7')->where('tarikh', '=', $current->toDateString())->orderBy('nosiri', 'desc')->first();
|
||||
|
||||
return response()->json($nosiri);
|
||||
}
|
||||
|
||||
public function create(Request $request){
|
||||
public function create(Request $request)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw',$request->kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
$sag = Gadai::on($cawangan['mysql'])->where('norujukan',$request->norujukan)->first();
|
||||
$sag = Gadai::on($cawangan['mysql'])->where('norujukan', $request->norujukan)->first();
|
||||
|
||||
$transaction = TransactionOnline::on('mysql7')->create([
|
||||
'nokp' => $request->nokp,
|
||||
@@ -57,36 +60,38 @@ class TransactionOnlineController extends Controller
|
||||
'tarikh' => $current->toDateString(),
|
||||
'masa' => $current->toTimeString(),
|
||||
'customer_name' => $request->customer_name,
|
||||
'tempohbayar'=>$sag['tempoh'],
|
||||
'tempohbayar' => $sag['tempoh'],
|
||||
'jenisbayaran' => $request->jenisbayaran ? $request->jenisbayaran : 'A'
|
||||
]);
|
||||
|
||||
return response()->json($transaction,201);
|
||||
return response()->json($transaction, 201);
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request){
|
||||
$transaction = TransactionOnline::on('mysql7')->where('billplz_id','=',$request->billplz_id)->update(array(
|
||||
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);
|
||||
return response()->json($transaction, 200);
|
||||
}
|
||||
|
||||
public function updateTransactionOnline(){
|
||||
$transactions = TransactionOnline::on('mysql7')->where([['status','=','PAID'],['update_status',0]])->get();
|
||||
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){
|
||||
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($transaction->jenisbayaran == 'A'){
|
||||
if($gadai_data['hargajualan'] > 0){
|
||||
$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']);
|
||||
->where('kodcaw', '=', $transaction['kodcaw'])
|
||||
->first();
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])->where([['norujukan', $transaction['norujukan']], ['nokp', $transaction['nokp']]])->first();
|
||||
if ($transaction->jenisbayaran == 'A') {
|
||||
if ($gadai_data['hargajualan'] > 0) {
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +104,9 @@ class TransactionOnlineController extends Controller
|
||||
'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([
|
||||
TransactionOnline::on('mysql7')->where([['norujukan', $transaction['norujukan']], ['billplz_id', $transaction['billplz_id']]])->update([
|
||||
'update_status' => 1,
|
||||
'update_serahan' => 1
|
||||
]);
|
||||
@@ -110,47 +115,49 @@ class TransactionOnlineController extends Controller
|
||||
return response()->json('success');
|
||||
}
|
||||
|
||||
public function kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar){
|
||||
public function kiraupahTawarruq($kodcaw, $norujukan, $tempohbayar)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->first();
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$norujukan)
|
||||
->first();
|
||||
->where('norujukan', '=', $norujukan)
|
||||
->first();
|
||||
|
||||
$bilang_bln = $tempohbayar - $gadai_data['tempohbayar'];
|
||||
|
||||
$upahsemasa_raw = $bilang_bln * (($gadai_data['kadarupah']/100 )* $gadai_data['pinjaman']);
|
||||
$upahsemasa_raw = $bilang_bln * (($gadai_data['kadarupah'] / 100) * $gadai_data['pinjaman']);
|
||||
|
||||
$upah_semasa_round = number_format($upahsemasa_raw,2);
|
||||
$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);
|
||||
if (strpos($upah_semasa, ',')) {
|
||||
$upah_semasa = str_replace(',', '', $upah_semasa);
|
||||
}
|
||||
// $upah_semasa = floatval(preg_replace('/[^\d.]/', '', $upah_semasa));
|
||||
// $upah_semasa = floatval(preg_replace('/[^\d.]/', '', $upah_semasa));
|
||||
return $upah_semasa;
|
||||
}
|
||||
|
||||
public function kiraUpahRebet($kodcaw,$norujukan,$tempohbayar){
|
||||
public function kiraUpahRebet($kodcaw, $norujukan, $tempohbayar)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->first();
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$norujukan)
|
||||
->first();
|
||||
->where('norujukan', '=', $norujukan)
|
||||
->first();
|
||||
|
||||
$bilang_bln = $tempohbayar - $gadai_data['tempohbayar'];
|
||||
|
||||
$upahrebet_raw = $bilang_bln * (($gadai_data['kadarupah']/100 )* $gadai_data['bakipjm']);
|
||||
$upahrebet_raw = $bilang_bln * (($gadai_data['kadarupah'] / 100) * $gadai_data['bakipjm']);
|
||||
|
||||
$upah_rebet_round = number_format($upahrebet_raw,2);
|
||||
$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);
|
||||
if (strpos($upah_rebet, ',')) {
|
||||
$upah_rebet = str_replace(',', '', $upah_rebet);
|
||||
}
|
||||
// $upah_rebet = floatval(preg_replace('/[^\d.]/', '', $upah_rebet));
|
||||
// $upah_rebet = floatval(preg_replace('/[^\d.]/', '', $upah_rebet));
|
||||
|
||||
return $upah_rebet;
|
||||
}
|
||||
@@ -288,31 +295,32 @@ class TransactionOnlineController extends Controller
|
||||
// return response()->json("success",200);
|
||||
// }
|
||||
|
||||
public function updateGadaiMarhunOnline($kodcaw,$norujukan,$bayaran,$paid_at,$tempohbayar){
|
||||
public function updateGadaiMarhunOnline($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();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan', '=', $norujukan)->first();
|
||||
|
||||
if($tempohbayar == 0.0){
|
||||
if ($tempohbayar == 0.0) {
|
||||
$tempohbayar = $gadai['tempoh'];
|
||||
}
|
||||
|
||||
$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');
|
||||
$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']){
|
||||
if ($total_bayaran_semasa >= $gadai['bakiupah']) {
|
||||
$lelong_tawarruq = 0;
|
||||
}else{
|
||||
} else {
|
||||
$lelong_tawarruq = 1;
|
||||
}
|
||||
$onepercent = new OnePercentServices();
|
||||
|
||||
$old_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
$old_data = Gadai::on($cawangan['mysql'])->where('norujukan', '=', $norujukan)->first();
|
||||
$margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||
|
||||
$baki_hargajualan = $gadai['bakihargajualan'] - $bayaran;
|
||||
@@ -321,7 +329,7 @@ class TransactionOnlineController extends Controller
|
||||
|
||||
try {
|
||||
|
||||
DB::connection('mysql7')->transaction(function () use($norujukan,$gadai,$kodcaw,$current,$baki_hargajualan,$cawangan,$old_data,$lelong_tawarruq,$margin_semasa,$bayaran,$tempohbayar) {
|
||||
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',
|
||||
@@ -334,41 +342,41 @@ class TransactionOnlineController extends Controller
|
||||
'bakiharga' => $baki_hargajualan,
|
||||
]);
|
||||
|
||||
if($gadai['tempoh'] >= 12.0){
|
||||
if ($gadai['tempoh'] >= 12.0) {
|
||||
$tempoh = 12;
|
||||
}else{
|
||||
} else {
|
||||
$tempoh = $gadai['tempoh'];
|
||||
}
|
||||
$bilang_bln = $tempoh - $gadai['tempohbayar'];
|
||||
|
||||
if($gadai['tagbaru'] == 0){
|
||||
$upahsemasa = $this->kiraupahTawarruq($kodcaw,$norujukan,$tempohbayar);
|
||||
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);
|
||||
$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,
|
||||
]);
|
||||
'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);
|
||||
$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);
|
||||
$gadaionepercent = new Version2Gadai($kodcaw, $cawangan);
|
||||
|
||||
$upahsemasa = $gadaionepercent->kiraupahOnePercent($norujukan);
|
||||
$upahrebet = $gadaionepercent->kiraUpahRebet($norujukan);
|
||||
@@ -382,29 +390,29 @@ class TransactionOnlineController extends Controller
|
||||
$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,
|
||||
]);
|
||||
$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){
|
||||
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(
|
||||
$update_gadai = Gadai::on($cawangan['mysql'])->where('norujukan', '=', $norujukan)->update(array(
|
||||
'bakipjm' => $baki_pinjaman,
|
||||
'jbg' => 0,
|
||||
't_update' => $current->toDateString(),
|
||||
@@ -415,7 +423,7 @@ class TransactionOnlineController extends Controller
|
||||
));
|
||||
});
|
||||
|
||||
$new_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||
$new_data = Gadai::on($cawangan['mysql'])->where('norujukan', '=', $norujukan)->first();
|
||||
|
||||
$audit = new Audit();
|
||||
$audit->users = 'Online';
|
||||
@@ -428,34 +436,33 @@ class TransactionOnlineController extends Controller
|
||||
$audit->updated_at = $current;
|
||||
$audit->save();
|
||||
|
||||
if(!$transaction || !$transaction_upah) {
|
||||
if (!$transaction || !$transaction_upah) {
|
||||
throw new \Exception('One of the database operations failed.');
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
});
|
||||
}catch(\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Transaction failed: " . $e->getMessage());
|
||||
return response()->json("Transaction failed: " . $e->getMessage(),500);
|
||||
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){
|
||||
public function createAdvansur($kodcaw, $norujukan, $bayaran, $paid_at)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan',$norujukan)->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,
|
||||
'tarikh' => Carbon::parse($paid_at)->toDateString(),
|
||||
'noresit' => 0,
|
||||
'norujukan' => $norujukan,
|
||||
'nopelanggan' => $gadai['nopelanggan'],
|
||||
'nilaimarhun' => $gadai['nilaimarhun'],
|
||||
@@ -473,26 +480,28 @@ class TransactionOnlineController extends Controller
|
||||
'historygadaian' => $norujukan
|
||||
]);
|
||||
|
||||
return response()->json($create_advansur ,201);
|
||||
return response()->json($create_advansur, 201);
|
||||
}
|
||||
|
||||
public function getTransactionOnlineLogin(Request $request){
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id',$request->billplz_id)->get();
|
||||
public function getTransactionOnlineLogin(Request $request)
|
||||
{
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id', $request->billplz_id)->get();
|
||||
|
||||
return response()->json($transactionOnline);
|
||||
}
|
||||
|
||||
public function searchSAGOnline(Request $request){
|
||||
public function searchSAGOnline(Request $request)
|
||||
{
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
$boolmasa = false;
|
||||
$transaction_online = TransactionOnline::on('mysql7')->where([['norujukan',$request->norujukan],['status','PAID'],['update_status',0],['tarikh',$current->toDateString()]])->first();
|
||||
$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();
|
||||
$transaction_masa = TransactionOnline::on('mysql7')->where([['norujukan', $request->norujukan], ['status', 'NOT PAID'], ['tarikh', $current->toDateString()]])
|
||||
->orderBy('masa', 'desc')->first();
|
||||
|
||||
if($transaction_masa){
|
||||
if ($transaction_masa) {
|
||||
$carbonmasa = new Carbon($transaction_masa['masa']);
|
||||
$carbonmasaexpired = new Carbon($transaction_masa['masa']);
|
||||
$carbonmasaexpired->addMinutes(10);
|
||||
@@ -500,48 +509,50 @@ class TransactionOnlineController extends Controller
|
||||
$boolmasa = ($carbonmasaexpired->greaterThanOrEqualTo($current) && $carbonmasa->lessThanOrEqualTo($current)) ? true : false;
|
||||
}
|
||||
|
||||
if($transaction_online || $boolmasa){
|
||||
if ($transaction_online || $boolmasa) {
|
||||
return response()->json(true);
|
||||
}else{
|
||||
} else {
|
||||
return response()->json(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function getListUnsuccessful(){
|
||||
$list = TransactionOnline::on('mysql7')->where('status','NOT PAID')->orderBy('id', 'desc')->take(10)->get();
|
||||
public function getListUnsuccessful()
|
||||
{
|
||||
$list = TransactionOnline::on('mysql7')->where('status', 'NOT PAID')->orderBy('id', 'desc')->take(10)->get();
|
||||
|
||||
return response()->json($list);
|
||||
}
|
||||
|
||||
public function updateUnsuccessfulTransaction(Request $request){
|
||||
$transaction = TransactionOnline::on('mysql7')->where('billplz_id','=',$request->billplz_id)->update(array(
|
||||
public function updateUnsuccessfulTransaction(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);
|
||||
return response()->json($transaction, 200);
|
||||
}
|
||||
|
||||
public function CustomerInfo(Request $request){
|
||||
public function CustomerInfo(Request $request)
|
||||
{
|
||||
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
$gadai_all = [];
|
||||
$akanlelongarray = [];
|
||||
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
foreach ($cawangan_all as $index => $cawangan) {
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['sttebus','=',''],['taglel',0],['nokp','=',$request->ic]])
|
||||
->orderBy('t_gadai','desc')
|
||||
->get()->toArray();
|
||||
->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 (sizeof($gadai) != 0) {
|
||||
foreach ($gadai as $gad) {
|
||||
|
||||
if($gad['tagbaru'] == 1){
|
||||
if ($gad['tagbaru'] == 1) {
|
||||
$jenis = 'onepercent';
|
||||
}else{
|
||||
} else {
|
||||
$jenis = 'asal';
|
||||
}
|
||||
|
||||
@@ -549,35 +560,33 @@ class TransactionOnlineController extends Controller
|
||||
'jeniskeuntungan' => $jenis
|
||||
]);
|
||||
|
||||
$result = (new TebusController)->upahTawarruq($gad['kodcaw'],$gad['norujukan'],$array_utg);
|
||||
$result = (new TebusController)->upahTawarruq($gad['kodcaw'], $gad['norujukan'], $array_utg);
|
||||
|
||||
if($jenis == 'onepercent') {
|
||||
if ($jenis == 'onepercent') {
|
||||
$gad['keuntungan'] = $result['pendapatan'];
|
||||
} else {
|
||||
$gad['keuntungan'] = $result;
|
||||
}
|
||||
array_push($gadai_all,$gad);
|
||||
array_push($gadai_all, $gad);
|
||||
}
|
||||
}
|
||||
|
||||
if($cawangan['tagarrahnbid'] == 1){
|
||||
if ($cawangan['tagarrahnbid'] == 1) {
|
||||
$akanlelong = Gadai::on($cawangan['mysql'])
|
||||
->where([['sttebus','=', ''],['taglel',1],['nokp','=',$request->ic]])
|
||||
->get()->toArray();
|
||||
}
|
||||
else{
|
||||
->where([['sttebus', '=', ''], ['taglel', 1], ['nokp', '=', $request->ic]])
|
||||
->get()->toArray();
|
||||
} else {
|
||||
$akanlelong = Gadai::on($cawangan['mysql'])
|
||||
->where([['sttebus','=', ''],['taglel',1],['nokp','=',$request->ic]])
|
||||
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->get()->toArray();
|
||||
->where([['sttebus', '=', ''], ['taglel', 1], ['nokp', '=', $request->ic]])
|
||||
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->get()->toArray();
|
||||
}
|
||||
|
||||
if(sizeof($akanlelong) != 0){
|
||||
foreach($akanlelong as $lelong)
|
||||
{
|
||||
$result = (new TebusController)->kiraupahTawarruq($lelong['kodcaw'],$lelong['norujukan'],$array_utg);
|
||||
if (sizeof($akanlelong) != 0) {
|
||||
foreach ($akanlelong as $lelong) {
|
||||
$result = (new TebusController)->kiraupahTawarruq($lelong['kodcaw'], $lelong['norujukan'], $array_utg);
|
||||
$lelong['keuntungan'] = $result;
|
||||
array_push($akanlelongarray,$lelong);
|
||||
array_push($akanlelongarray, $lelong);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,31 +595,36 @@ class TransactionOnlineController extends Controller
|
||||
array(
|
||||
'gadai' => $gadai_all,
|
||||
'lelong' => $akanlelongarray
|
||||
),200);
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function updateTagPortal(Request $request){
|
||||
$transaction = TransactionOnline::on('mysql7')->where('billplz_id','=',$request->billplz_id)->update(array(
|
||||
public function updateTagPortal(Request $request)
|
||||
{
|
||||
$transaction = TransactionOnline::on('mysql7')->where('billplz_id', '=', $request->billplz_id)->update(array(
|
||||
'tagportal' => 1
|
||||
));
|
||||
|
||||
return response()->json($transaction,200);
|
||||
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';
|
||||
$gadai = (new GadaiController())->showOneGadaibyRujukanAndCawangan($kodcaw, $norujukan)
|
||||
->getData()[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();
|
||||
$request_upah_tawarruq = new Request(['jeniskeuntungan' => $jenis_keuntungan]);
|
||||
$request_upah_rebet_tawarruq = new Request(['jeniskeuntungan' => $jenis_keuntungan]);
|
||||
|
||||
if($jenis_keuntungan === 'onepercent'){
|
||||
$upah_tawarruq = (new TebusController())->upahTawarruq($kodcaw, $norujukan, $request_upah_tawarruq);
|
||||
$upah_rebet_tawarruq = (new TebusController())->upahRebetTawarruq($kodcaw, $norujukan, $request_upah_rebet_tawarruq);
|
||||
|
||||
if ($jenis_keuntungan === 'onepercent') {
|
||||
$ujrah_sebenar = (float)$upah_tawarruq['ujrah'];
|
||||
$ujrah_rebet = $ujrah_sebenar - (float)$upah_rebet_tawarruq['ujrah'];
|
||||
|
||||
@@ -624,10 +638,9 @@ class TransactionOnlineController extends Controller
|
||||
'ujrah_sebenar' => (float)$upah_tawarruq,
|
||||
'ujrah_rebet' => (float)$upah_rebet_tawarruq,
|
||||
];
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error($th);
|
||||
return $th;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user