This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class PeriodeHelper
|
||||
{
|
||||
public static function getPeriodeRange($month, $year)
|
||||
{
|
||||
$month = (int) date('m', strtotime($month));
|
||||
$year = (int) $year;
|
||||
/**
|
||||
* Mendapatkan rentang tanggal fisik pengakuan untuk sebuah periode akuntansi (Bulan & Tahun)
|
||||
* Contoh: Periode "april 2026" -> Start: 11 April 2026, End: 13 Mei 2026 (Closing Date)
|
||||
*/
|
||||
public static function getPeriodeRange(string $month, int $year): array
|
||||
{
|
||||
// 1. Tentukan tanggal 11 di bulan dan tahun yang dipilih
|
||||
$startDate = Carbon::parse("11 $month $year")->startOfDay()->toDateTimeString();
|
||||
|
||||
// Jika Januari, periode dimulai dari 11 Januari hingga 10 Februari
|
||||
$start = Carbon::create($year, $month, 11)->startOfDay();
|
||||
$end = $start->copy()->addMonth()->subDay()->endOfDay();
|
||||
// 2. Tentukan tanggal 13 di bulan berikutnya (Bulan berjalan + 1)
|
||||
$endDate = Carbon::parse("13 $month $year")->addMonth()->endOfDay()->toDateTimeString();
|
||||
|
||||
return [$start, $end];
|
||||
}
|
||||
}
|
||||
return [$startDate, $endDate];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user