fix byrn keuntungan ujrah portal
This commit is contained in:
@@ -15,6 +15,9 @@ 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;
|
||||
|
||||
@@ -80,7 +83,7 @@ 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']);
|
||||
}
|
||||
@@ -151,7 +154,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 +298,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 +313,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',
|
||||
@@ -219,23 +339,59 @@ class TransactionOnlineController extends Controller
|
||||
$tempoh = $gadai['tempoh'];
|
||||
}
|
||||
$bilang_bln = $tempoh - $gadai['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);
|
||||
$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['margin_semasa']);
|
||||
$onepercentasal = $gadai['pinjaman'] * (1/100);
|
||||
|
||||
$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,
|
||||
]);
|
||||
$gadaionepercent = new Version2Gadai($kodcaw,$cawangan);
|
||||
|
||||
$upahsemasa = $gadaionepercent->kiraupahOnePercent($norujukan);
|
||||
$upahrebet = $gadaionepercent->kiraUpahRebet($norujukan);
|
||||
$baki_bayaran = $bayaran - $upahsemasa;
|
||||
|
||||
$onepercentservices = new Calculation();
|
||||
$transaction_upah = TransaksiKeuntungan::on('mysql7')->create([
|
||||
'norujukan' => $norujukan,
|
||||
'bayaran_keuntungan' => $upahsemasa,
|
||||
'bayaran_pembiayaan' => $baki_bayaran,
|
||||
'keuntungan_rebet'=> $upahrebet,
|
||||
'tarikh_bayaran'=> $current,
|
||||
'kodcaw'=> $kodcaw,
|
||||
'ujrah' => $onepercentservices->getRoundedMethod($keuntungan['ujrah'] * $bilang_bln),
|
||||
'ujrah_rebet' => $onepercentservices->getRoundedMethod($ujrahasal*$bilang_bln),
|
||||
'onepercent' => $onepercentservices->getRoundedMethod($onepercentasal * $bilang_bln),
|
||||
'onepercent_rebet' => $onepercentservices->getRoundedMethod($keuntungan['onepercent'] * $bilang_bln),
|
||||
'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;
|
||||
@@ -267,6 +423,7 @@ class TransactionOnlineController extends Controller
|
||||
if(!$transaction || !$transaction_upah) {
|
||||
throw new \Exception('One of the database operations failed.');
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
@@ -276,7 +433,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){
|
||||
@@ -368,9 +526,11 @@ 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{
|
||||
|
||||
@@ -119,6 +119,7 @@ $router->group(['prefix'=>'api'], function () use ($router){
|
||||
$router->get('tebus/laporan/{kodcaw}/{tarikh}',['uses'=>'TebusController@getLaporanTebus']);
|
||||
$router->get('tebus/laporanjenistawarruq/{kodcaw}',['uses'=>'TebusController@getLaporanTebusPengasingan']);
|
||||
$router->get('upahtawarruqbytarikh',['uses'=>'TebusController@upahTawarruqByTarikh']);
|
||||
$router->get('upahtawarruqujrah/{kodcaw}/{norujukan}/{jeniskeuntungan}',['uses'=>'TebusController@kiraupahTawarruq']);
|
||||
|
||||
//Tebus Ujrah (Laporan Range Date)
|
||||
$router->get('tebusujrah/laporan/{kodcaw}',['uses'=>'TebusController@getLaporanTebusUjrah']);
|
||||
|
||||
Reference in New Issue
Block a user