update interest history
This commit is contained in:
parent
9ad98da843
commit
6baeda70c4
@ -1,31 +1,44 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
/**
|
||||||
/**
|
* Run the migrations.
|
||||||
* Run the migrations.
|
*/
|
||||||
*/
|
public function up()
|
||||||
public function up(): void
|
: void
|
||||||
{
|
{
|
||||||
Schema::create('interest_histories', function (Blueprint $table) {
|
Schema::create('interest_histories', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('nomor_pinjaman',20);
|
$table->string('nomor_pinjaman', 20);
|
||||||
$table->string('periode_bunga',6);
|
$table->string('periode_bunga', 8);
|
||||||
$table->string('nilai_bunga_intra');
|
$table->date('tanggal_awal');
|
||||||
$table->string('nilai_bunga_extra');
|
$table->date('tanggal_akhir');
|
||||||
$table->timestamps();
|
$table->string('hari_bunga');
|
||||||
});
|
$table->string('nilai_bunga');
|
||||||
}
|
$table->string('hari_denda');
|
||||||
|
$table->string('nilai_denda');
|
||||||
|
$table->string('total_kewajiban');
|
||||||
|
$table->string('suku_bunga');
|
||||||
|
$table->string('suku_bunga_denda');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
$table->unsignedBigInteger('created_by')->nullable();
|
||||||
|
$table->unsignedBigInteger('updated_by')->nullable();
|
||||||
|
$table->unsignedBigInteger('deleted_by')->nullable();
|
||||||
|
$table->unsignedBigInteger('authorized_by')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the migrations.
|
* Reverse the migrations.
|
||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down()
|
||||||
{
|
: void
|
||||||
Schema::dropIfExists('interest_histories');
|
{
|
||||||
}
|
Schema::dropIfExists('interest_histories');
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
@ -10,7 +10,14 @@
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'nomor_pinjaman',
|
'nomor_pinjaman',
|
||||||
'periode_bunga',
|
'periode_bunga',
|
||||||
'nilai_bunga_intra',
|
'tanggal_awal',
|
||||||
'nilai_bunga_extra',
|
'tanggal_akhir',
|
||||||
|
'hari_bunga',
|
||||||
|
'nilai_bunga',
|
||||||
|
'hari_denda',
|
||||||
|
'nilai_denda',
|
||||||
|
'total_kewajiban',
|
||||||
|
'suku_bunga',
|
||||||
|
'suku_bunga_denda',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Carbon\CarbonInterval;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@ -17,6 +18,7 @@
|
|||||||
use Modules\Writeoff\Entities\DetailPenagihan;
|
use Modules\Writeoff\Entities\DetailPenagihan;
|
||||||
use Modules\Writeoff\Entities\FacilityType;
|
use Modules\Writeoff\Entities\FacilityType;
|
||||||
use Modules\Writeoff\Entities\HapusBuku;
|
use Modules\Writeoff\Entities\HapusBuku;
|
||||||
|
use Modules\Writeoff\Entities\InterestHistory;
|
||||||
use Modules\Writeoff\Entities\LoanType;
|
use Modules\Writeoff\Entities\LoanType;
|
||||||
use Modules\Writeoff\Entities\Rekening;
|
use Modules\Writeoff\Entities\Rekening;
|
||||||
use Modules\Writeoff\Http\Requests\HapusBuku\StoreHapusBukuRequest;
|
use Modules\Writeoff\Http\Requests\HapusBuku\StoreHapusBukuRequest;
|
||||||
@ -46,7 +48,7 @@
|
|||||||
if (is_null($this->user) || !$this->user->can('pencatatan.read')) {
|
if (is_null($this->user) || !$this->user->can('pencatatan.read')) {
|
||||||
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
||||||
}
|
}
|
||||||
|
$this->hitungBunga();
|
||||||
if ($request->rekening) {
|
if ($request->rekening) {
|
||||||
return redirect()->route('pencatatan.hapus_buku.create', ['rekening' => $request->rekening]);
|
return redirect()->route('pencatatan.hapus_buku.create', ['rekening' => $request->rekening]);
|
||||||
} else {
|
} else {
|
||||||
@ -61,6 +63,7 @@
|
|||||||
|
|
||||||
public function store(StoreHapusBukuRequest $request)
|
public function store(StoreHapusBukuRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
if ($validated) {
|
if ($validated) {
|
||||||
@ -125,8 +128,9 @@
|
|||||||
echo json_encode(['status' => 'error', 'message' => 'Data Sedang Menunggu Approval']);
|
echo json_encode(['status' => 'error', 'message' => 'Data Sedang Menunggu Approval']);
|
||||||
} else {
|
} else {
|
||||||
Approval::create($approval);
|
Approval::create($approval);
|
||||||
echo json_encode(['status' => 'success',
|
echo json_encode([
|
||||||
'message' => 'Data Berhasil Di Input, Menunggu Approval'
|
'status' => 'success',
|
||||||
|
'message' => 'Data Berhasil Di Input, Menunggu Approval'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +177,10 @@
|
|||||||
->get()
|
->get()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$jaminan = DetailJaminan::with('guaranteeType')->where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)->get();
|
$jaminan = DetailJaminan::with('guaranteeType')
|
||||||
$bayar = DetailPembayaran::where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)->get();
|
->where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)
|
||||||
|
->get();
|
||||||
|
$bayar = DetailPembayaran::where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)->get();
|
||||||
$penagihan = DetailPenagihan::where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)->get();
|
$penagihan = DetailPenagihan::where('nomor_pinjaman', $hapusbuku->nomor_pinjaman)->get();
|
||||||
|
|
||||||
return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency', 'rekening', 'totalbayar', 'hapusbuku', 'jaminan', 'bayar', 'penagihan'));
|
return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency', 'rekening', 'totalbayar', 'hapusbuku', 'jaminan', 'bayar', 'penagihan'));
|
||||||
@ -193,6 +199,157 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hitungBunga()
|
||||||
|
{
|
||||||
|
$hapusbuku = HapusBuku::where('status', 1)->get();
|
||||||
|
$suku_bunga_extra = 35;
|
||||||
|
$decimal = 2;
|
||||||
|
$now = Carbon::today();
|
||||||
|
|
||||||
|
foreach ($hapusbuku as $key => $value) {
|
||||||
|
$nomor_pinjaman = $value->nomor_pinjaman;
|
||||||
|
$tgl_wo = Carbon::parse($value->tanggal_hapus_buku);
|
||||||
|
$hari_wo = $now->diffInDays($tgl_wo);
|
||||||
|
$day_wo = $tgl_wo->day;
|
||||||
|
|
||||||
|
|
||||||
|
$tgl = $tgl_wo;
|
||||||
|
$bunga_ekstra = 0;
|
||||||
|
$bunga_non_ekstra = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while ($tgl <= $now) {
|
||||||
|
$awal = $tgl;
|
||||||
|
echo '1. '.$awal;
|
||||||
|
$id = $awal->format('Ymd');
|
||||||
|
|
||||||
|
$hist = InterestHistory::where('nomor_pinjaman', $nomor_pinjaman)
|
||||||
|
->where('periode_bunga', $id)
|
||||||
|
->get()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$cnt = 0;
|
||||||
|
if ($hist) {
|
||||||
|
$cnt = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$base = $value->baki_debet;
|
||||||
|
$sk_bng = $value->suku_bunga;
|
||||||
|
|
||||||
|
if($cnt == 1) {
|
||||||
|
$base = $hist->total_kewajiban;
|
||||||
|
$sk_bng = $hist->suku_bunga;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (in_array($awal->format('m'), ['01', '03', '05', '07', '08', '10', '12'])) {
|
||||||
|
$n = 31;
|
||||||
|
} else if (in_array($awal->format('m'), ['04', '06', '09', '11'])) {
|
||||||
|
$n = 30;
|
||||||
|
} else {
|
||||||
|
$n = 28;
|
||||||
|
if ($awal->format('Y') % 4 == 0) {
|
||||||
|
$n = 29;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($day_wo <= 28) {
|
||||||
|
$tgl_ = $tgl->addDays($n);
|
||||||
|
} else if ($day_wo == 29) {
|
||||||
|
$tgl_ = $tgl->addMonths(1);
|
||||||
|
if ($tgl->format('dmy') == '2802') {
|
||||||
|
$tgl_ = $tgl->addDays($day_wo);
|
||||||
|
}
|
||||||
|
} else if ($day_wo == 30) {
|
||||||
|
$tgl_ = $tgl->addMonths(1);
|
||||||
|
if ($tgl->format('dmy') == '2802') {
|
||||||
|
$tgl_ = $tgl->addDays($day_wo);
|
||||||
|
} else {
|
||||||
|
if ($tgl->addDay()->format('d') == '01') {
|
||||||
|
$tgl_ = $tgl_->subDay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* if($tgl->addMonths(1)->format('d') == '02') {
|
||||||
|
$tgl_ = $tgl->addMonths(1);
|
||||||
|
} else {
|
||||||
|
$tgl_ = $tgl->addMonths(1);
|
||||||
|
if ($tgl->addDay()->format('d') == '01') {
|
||||||
|
$tgl_ = $tgl_->subDay();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
$tgl_ = $tgl->addMonths(1);
|
||||||
|
echo ' 2. '.$awal;exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$akhir = $tgl_->subDay();
|
||||||
|
//echo $akhir;
|
||||||
|
|
||||||
|
echo $akhir->diffInDays($awal);exit;
|
||||||
|
$hari_b = $akhir->diffInDays($awal) + 1;
|
||||||
|
$hari_d = $now->subDay()->diffInDays($akhir);
|
||||||
|
|
||||||
|
if ($akhir->addDay()->format('dmy') == $now->format('dmy')) {
|
||||||
|
$hari_d = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//bunga amount due
|
||||||
|
//echo $hari_b . 'b ' . $hari_d . 'd ' . $base . 'bs ' . $sk_bng . ' ' . $suku_bunga_extra . '<br>';exit;
|
||||||
|
$temp_non = ($base * ($sk_bng / 100) * $hari_b) / 360;
|
||||||
|
$bunga_non_ekstra += $temp_non;
|
||||||
|
|
||||||
|
//denda
|
||||||
|
$temp = ($temp_non * ($suku_bunga_extra / 100) * $hari_d) / 360;
|
||||||
|
$bunga_ekstra += $temp;
|
||||||
|
|
||||||
|
//bunga berjalan
|
||||||
|
$tagihan_lain = $temp_non;
|
||||||
|
|
||||||
|
|
||||||
|
InterestHistory::updateOrCreate([
|
||||||
|
'nomor_pinjaman' => $nomor_pinjaman,
|
||||||
|
'periode_bunga' => $id,
|
||||||
|
], [
|
||||||
|
'tanggal_awal' => $awal,
|
||||||
|
'tanggal_akhir' => $akhir,
|
||||||
|
'hari_bunga' => $hari_b,
|
||||||
|
'nilai_bunga' => round($temp_non, $decimal),
|
||||||
|
'hari_denda' => $hari_d,
|
||||||
|
'nilai_denda' => round($temp, $decimal),
|
||||||
|
'total_kewajiban' => $value->baki_debet,
|
||||||
|
'suku_bunga' => $value->suku_bunga,
|
||||||
|
'suku_bunga_denda' => $suku_bunga_extra
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bunga_intra = ($value->baki_debet * ($value->suku_bunga / 100) * $hari_wo) / 360;
|
||||||
|
$bunga_non_ekstra = $bunga_non_ekstra - $tagihan_lain;
|
||||||
|
|
||||||
|
$bunga_intra = round($bunga_intra, $decimal);
|
||||||
|
$bunga_ekstra = round($bunga_ekstra, $decimal);
|
||||||
|
$bunga_non_ekstra = round($bunga_non_ekstra, $decimal);
|
||||||
|
$tagihan_lain = round($tagihan_lain, $decimal);
|
||||||
|
|
||||||
|
$total_all = $value->total_kewajiban + $bunga_intra + $bunga_ekstra + $value->denda + $value->biaya_lain;
|
||||||
|
|
||||||
|
HapusBuku::where('nomor_pinjaman', $nomor_pinjaman)->update([
|
||||||
|
'bunga_intra' => $bunga_intra,
|
||||||
|
'bunga_ekstra' => $bunga_ekstra,
|
||||||
|
'bunga_non_ekstra' => $bunga_non_ekstra,
|
||||||
|
'tagihan_lain' => $tagihan_lain,
|
||||||
|
'total_all_kewajiban' => $total_all
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
public function update(UpdateHapusBukuRequest $request, $id)
|
public function update(UpdateHapusBukuRequest $request, $id)
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
@ -261,7 +418,9 @@
|
|||||||
echo json_encode(['status' => 'error', 'message' => 'Data Sedang Menunggu Approval']);
|
echo json_encode(['status' => 'error', 'message' => 'Data Sedang Menunggu Approval']);
|
||||||
} else {
|
} else {
|
||||||
Approval::create($approval);
|
Approval::create($approval);
|
||||||
echo json_encode(['status' => 'success', 'message' => 'Data Berhasil Di Update, Menunggu Approval']);
|
echo json_encode(['status' => 'success',
|
||||||
|
'message' => 'Data Berhasil Di Update, Menunggu Approval'
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,35 +430,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
|
|
||||||
public function hitungBunga(){
|
|
||||||
$hapusbuku = HapusBuku::all();
|
|
||||||
$suku_bunga_extra = 35;
|
|
||||||
|
|
||||||
foreach($hapusbuku as $key => $value){
|
|
||||||
// Define your dates (replace with your actual dates)
|
|
||||||
$startDate = Carbon::parse($value->tanggal_hapus_buku); // Or use any date variable
|
|
||||||
$endDate = Carbon::today();
|
|
||||||
|
|
||||||
// Calculate the difference in days
|
|
||||||
$daysDiff = $startDate->diffInDays($endDate);
|
|
||||||
|
|
||||||
$bunga = $value->suku_bunga / 100 * $value->baki_debet;
|
|
||||||
$value->jumlah_bunga = $bunga;
|
|
||||||
$value->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user