update online
This commit is contained in:
@@ -11,6 +11,9 @@ use App\Cawangan;
|
|||||||
use App\GlDetail;
|
use App\GlDetail;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Services\OnePercentServices;
|
||||||
|
use Log;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
use App\Http\Controllers\TebusController as TebusController;
|
use App\Http\Controllers\TebusController as TebusController;
|
||||||
|
|
||||||
@@ -167,6 +170,9 @@ class TransactionOnlineController extends Controller
|
|||||||
}else{
|
}else{
|
||||||
$lelong_tawarruq = 1;
|
$lelong_tawarruq = 1;
|
||||||
}
|
}
|
||||||
|
$onepercent = new OnePercentServices();
|
||||||
|
|
||||||
|
$old_data = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->first();
|
||||||
|
|
||||||
$baki_hargajualan = $gadai['bakihargajualan'] - $bayaran;
|
$baki_hargajualan = $gadai['bakihargajualan'] - $bayaran;
|
||||||
|
|
||||||
@@ -174,35 +180,92 @@ class TransactionOnlineController extends Controller
|
|||||||
|
|
||||||
$baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran;
|
$baki_pinjaman = $gadai['bakipjm'] - $baki_bayaran;
|
||||||
|
|
||||||
$transaction = Transaction::on('mysql7')->create([
|
$margin_semasa = ($gadai['bakipjm'] / $gadai['nilaimarhun']) * 100;
|
||||||
'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([
|
$keuntungan = $onepercent->kiraanKeuntunganSebenar($gadai['bakipjm'],$gadai['nilaimarhun'],$gadai['kadarupah'],$margin_semasa);
|
||||||
'norujukan' => $norujukan,
|
$ujrahasal = $onepercent->kiraanUjrahSebenar($gadai['nilaimarhun'],$gadai['kadarupah'],$gadai['margin_semasa']);
|
||||||
'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(
|
$onepercentasal = $gadai['pinjaman'] * (1/100);
|
||||||
'bakipjm' => $baki_pinjaman,
|
|
||||||
'jbg' => 0,
|
try {
|
||||||
't_update' => Carbon::parse($paid_at)->toDateString(),
|
|
||||||
'bakihargajualan' => $baki_hargajualan,
|
DB::connection('mysql7')->transaction(function () use($onepercentasal,$ujrahasal,$keuntungan,$norujukan,$gadai,$request,$kodcaw,$current,$baki_hargajualan,$upahsemasa,$baki_bayaran,$upahrebet,$cawangan,$old_data,$baki_pinjaman,$lelong_tawarruq,$margin_semasa) {
|
||||||
'tempohbayar' => $tempohbayar,
|
|
||||||
'lelong_tawarruq' => $lelong_tawarruq
|
$transaction = Transaction::on('mysql7')->create([
|
||||||
));
|
'trans_type' => 'A',
|
||||||
return response()->json($update_gadai, 200);
|
'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 createAdvansur($kodcaw,$norujukan,$bayaran,$paid_at){
|
public function createAdvansur($kodcaw,$norujukan,$bayaran,$paid_at){
|
||||||
|
|||||||
Reference in New Issue
Block a user