fix bug periode
This commit is contained in:
@@ -28,6 +28,7 @@ use App\Helpers\BudgetHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\BrevoService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class FormVehicleController extends Controller
|
||||
{
|
||||
@@ -36,10 +37,26 @@ class FormVehicleController extends Controller
|
||||
$this->checkAuthorization(auth()->user(), ['forms.vehicle.view']);
|
||||
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
||||
$startDay = (int) env('STARTING_DATE', 11);
|
||||
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||
|
||||
$forms = FormVehicleRunningCost::whereBetween('tanggal', [$startDate, $closingDateNextMonth])
|
||||
// Referensi waktu sekarang
|
||||
$now = Carbon::now();
|
||||
|
||||
// Tentukan periode
|
||||
if ($now->day >= $startDay) {
|
||||
// Mulai dari tanggal START bulan ini
|
||||
$startDate = Carbon::create($now->year, $now->month, $startDay)->startOfDay();
|
||||
// Sampai tanggal CLOSING bulan depan
|
||||
$closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay)->endOfDay();
|
||||
} else {
|
||||
// Mulai dari tanggal START bulan lalu
|
||||
$startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay)->startOfDay();
|
||||
// Sampai tanggal CLOSING bulan ini
|
||||
$closingDate = Carbon::create($now->year, $now->month, $closingDay)->endOfDay();
|
||||
}
|
||||
|
||||
$forms = FormVehicleRunningCost::whereBetween('tanggal', [$startDate, $closingDate])
|
||||
->orderBy('tanggal', 'desc')
|
||||
->with('user')
|
||||
->get();
|
||||
@@ -129,11 +146,25 @@ class FormVehicleController extends Controller
|
||||
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
||||
]);
|
||||
|
||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
||||
$tanggal = Carbon::parse($request->tanggal);
|
||||
$startDay = (int) env('STARTING_DATE', 11);
|
||||
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||
|
||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
||||
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($now->day >= $startDay) {
|
||||
// Periode berjalan dari bulan ini sampai bulan depan
|
||||
$startDate = Carbon::create($now->year, $now->month, $startDay);
|
||||
$closingDate = Carbon::create($now->copy()->addMonth()->year, $now->copy()->addMonth()->month, $closingDay);
|
||||
} else {
|
||||
// Periode berjalan dari bulan lalu sampai bulan ini
|
||||
$startDate = Carbon::create($now->copy()->subMonth()->year, $now->copy()->subMonth()->month, $startDay);
|
||||
$closingDate = Carbon::create($now->year, $now->month, $closingDay);
|
||||
}
|
||||
|
||||
if ($tanggal->lt($startDate) || $tanggal->gt($closingDate)) {
|
||||
session()->flash('error', "Gagal, tanggal tidak berada dalam periode input: {$startDate->format('d M')} - {$closingDate->format('d M')}");
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user