fix bug periode
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
// Jika Januari, periode dimulai dari 11 Januari hingga 10 Februari
|
||||||
|
$start = Carbon::create($year, $month, 11)->startOfDay();
|
||||||
|
$end = $start->copy()->addMonth()->subDay()->endOfDay();
|
||||||
|
|
||||||
|
return [$start, $end];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -249,7 +249,6 @@ class WhatsappHelper
|
|||||||
return $response->getBody()->getContents();
|
return $response->getBody()->getContents();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
|
AuditTrailHelper::AddAuditTrail('Error', 'Failed to send WhatsApp message at Form (' . $expense_number . ')');
|
||||||
dd($e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use Illuminate\Support\Carbon;
|
|||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use App\Models\Kategori;
|
use App\Models\Kategori;
|
||||||
use App\Models\BudgetControlLog;
|
use App\Models\BudgetControlLog;
|
||||||
|
use App\Helpers\PeriodeHelper;
|
||||||
|
|
||||||
class ReportController extends Controller
|
class ReportController extends Controller
|
||||||
{
|
{
|
||||||
@@ -621,53 +622,60 @@ class ReportController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateJurnal() {
|
|
||||||
|
public function generateJurnal()
|
||||||
|
{
|
||||||
$params = request()->all();
|
$params = request()->all();
|
||||||
|
|
||||||
$kategoris = Kategori::all();
|
$kategoris = Kategori::all();
|
||||||
$kategori_bca = Kategori::where('name', 'Cash in Bank BCA')->first();
|
$kategori_bca = Kategori::where('name', 'Cash in Bank BCA')->first();
|
||||||
$cabang = Cabang::with('cost')->where('code', $params['cabang'])->first();
|
$cabang = Cabang::with('cost')->where('code', $params['cabang'])->firstOrFail();
|
||||||
|
|
||||||
$year = $params['year'];
|
$year = $params['year'];
|
||||||
$month = $params['month'];
|
$month = $params['month']; // format: angka atau teks bulan (pastikan valid)
|
||||||
|
|
||||||
// get last data
|
// Hitung range periode (11 bulan_ini - 10 bulan_depan)
|
||||||
$budget = BudgetControlLog::where('cabang_id', $cabang->id)->where('periode_year', $year)->where('periode_month', $month)->orderBy('created_at', 'desc')->first();
|
[$startDate, $endDate] = PeriodeHelper::getPeriodeRange($month, $year);
|
||||||
|
|
||||||
|
// Ambil data terakhir dari log budget
|
||||||
|
$budget = BudgetControlLog::where('cabang_id', $cabang->id)
|
||||||
|
->where('periode_year', $year)
|
||||||
|
->where('periode_month', $month)
|
||||||
|
->orderBy('created_at', 'desc')
|
||||||
|
->first();
|
||||||
|
|
||||||
$userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
|
$userIds = UserHasCabang::where('cabang_id', $cabang->id)->pluck('user_id');
|
||||||
|
|
||||||
// Fetch all relevant forms in one batch
|
// Fetch semua forms berdasarkan periode range
|
||||||
$forms = [
|
$forms = [
|
||||||
'Up Country' => FormUpCountry::whereIn('user_id', $userIds)
|
'Up Country' => FormUpCountry::whereIn('user_id', $userIds)
|
||||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
->whereBetween('tanggal', [$startDate, $endDate])
|
||||||
->whereYear('tanggal', '=', $year)
|
->whereIn('status', ['Approved', 'On Progress'])
|
||||||
->whereIn('status', ['Approved', 'Closed'])
|
|
||||||
->get(),
|
->get(),
|
||||||
|
|
||||||
'Vehicle Running Cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)
|
'Vehicle Running Cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)
|
||||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
->whereBetween('tanggal', [$startDate, $endDate])
|
||||||
->whereYear('tanggal', '=', $year)
|
->whereIn('status', ['Approved', 'On Progress'])
|
||||||
->whereIn('status', ['Approved', 'Closed'])
|
|
||||||
->get(),
|
->get(),
|
||||||
|
|
||||||
'Entertainment' => FormEntertaimentPresentation::whereIn('user_id', $userIds)
|
'Entertainment' => FormEntertaimentPresentation::whereIn('user_id', $userIds)
|
||||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
->whereBetween('tanggal', [$startDate, $endDate])
|
||||||
->whereYear('tanggal', '=', $year)
|
->whereIn('status', ['Approved', 'On Progress'])
|
||||||
->whereIn('status', ['Approved', 'Closed'])
|
|
||||||
->get(),
|
->get(),
|
||||||
|
|
||||||
'Meeting / Seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)
|
'Meeting / Seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)
|
||||||
->whereMonth('created_at', '=', date('m', strtotime($month)))
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
->whereYear('created_at', '=', $year)
|
->whereIn('status', ['Approved', 'On Progress'])
|
||||||
->whereIn('status', ['Approved', 'Closed'])
|
|
||||||
->get(),
|
->get(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// Fetch 'Others' forms by kategori
|
// Forms "Others" dikelompokkan berdasarkan kategori
|
||||||
$otherForms = FormOthers::whereIn('user_id', $userIds)
|
$otherForms = FormOthers::whereIn('user_id', $userIds)
|
||||||
->whereMonth('tanggal', '=', date('m', strtotime($month)))
|
->whereBetween('tanggal', [$startDate, $endDate])
|
||||||
->whereYear('tanggal', '=', $year)
|
->whereIn('status', ['Approved', 'On Progress'])
|
||||||
->whereIn('status', ['Approved', 'Closed'])
|
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// Precompute totals for each category
|
// Total nominal per kategori
|
||||||
$nominals = [];
|
$nominals = [];
|
||||||
foreach ($kategoris as $item) {
|
foreach ($kategoris as $item) {
|
||||||
if (isset($forms[$item->name])) {
|
if (isset($forms[$item->name])) {
|
||||||
@@ -687,7 +695,7 @@ class ReportController extends Controller
|
|||||||
'month' => $month,
|
'month' => $month,
|
||||||
'kategori_bca' => $kategori_bca,
|
'kategori_bca' => $kategori_bca,
|
||||||
'nominals' => $nominals,
|
'nominals' => $nominals,
|
||||||
'budget' => $budget
|
'budget' => $budget,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use App\Helpers\BudgetHelper;
|
|||||||
use App\Helpers\NotificationHelper;
|
use App\Helpers\NotificationHelper;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Services\BrevoService;
|
use App\Services\BrevoService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class FormEntertainmentPresentationController extends Controller
|
class FormEntertainmentPresentationController extends Controller
|
||||||
{
|
{
|
||||||
@@ -36,10 +37,26 @@ class FormEntertainmentPresentationController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.entertainment.view']);
|
$this->checkAuthorization(auth()->user(), ['forms.entertainment.view']);
|
||||||
|
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
$forms = FormEntertaimentPresentation::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 = FormEntertaimentPresentation::whereBetween('tanggal', [$startDate, $closingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
->with('user')
|
->with('user')
|
||||||
->get();
|
->get();
|
||||||
@@ -128,11 +145,25 @@ class FormEntertainmentPresentationController extends Controller
|
|||||||
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
$tanggal = Carbon::parse($request->tanggal);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
$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();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use App\Helpers\BudgetHelper;
|
|||||||
use App\Helpers\NotificationHelper;
|
use App\Helpers\NotificationHelper;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Services\BrevoService;
|
use App\Services\BrevoService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class FormMeetingSeminarController extends Controller
|
class FormMeetingSeminarController extends Controller
|
||||||
{
|
{
|
||||||
@@ -36,10 +37,26 @@ class FormMeetingSeminarController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.meeting.view']);
|
$this->checkAuthorization(auth()->user(), ['forms.meeting.view']);
|
||||||
|
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
$forms = FormMeetingSeminar::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 = FormMeetingSeminar::whereBetween('tanggal', [$startDate, $closingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
->with('user')
|
->with('user')
|
||||||
->get();
|
->get();
|
||||||
@@ -131,12 +148,25 @@ class FormMeetingSeminarController extends Controller
|
|||||||
'bukti_hotel' => ['nullable', 'file', 'max:51200'],
|
'bukti_hotel' => ['nullable', 'file', 'max:51200'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$currentDate = $request->tanggal;
|
$tanggal = Carbon::parse($request->tanggal);
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
if ($currentDate < $startDate || $currentDate > $closingDateNextMonth) {
|
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
$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();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use App\Helpers\NotificationHelper;
|
|||||||
use App\Models\Cabang;
|
use App\Models\Cabang;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Services\BrevoService;
|
use App\Services\BrevoService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class FormOtherController extends Controller
|
class FormOtherController extends Controller
|
||||||
{
|
{
|
||||||
@@ -33,10 +34,27 @@ class FormOtherController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.other.view']);
|
$this->checkAuthorization(auth()->user(), ['forms.other.view']);
|
||||||
|
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
$forms = FormOthers::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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query data berdasarkan periode
|
||||||
|
$forms = FormOthers::whereBetween('tanggal', [$startDate, $closingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
->with('user')
|
->with('user')
|
||||||
->get();
|
->get();
|
||||||
@@ -126,11 +144,25 @@ class FormOtherController extends Controller
|
|||||||
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
$tanggal = Carbon::parse($request->tanggal);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
$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();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use App\Helpers\BudgetHelper;
|
|||||||
use App\Helpers\NotificationHelper;
|
use App\Helpers\NotificationHelper;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Services\BrevoService;
|
use App\Services\BrevoService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class FormUpCountryController extends Controller
|
class FormUpCountryController extends Controller
|
||||||
{
|
{
|
||||||
@@ -36,10 +37,26 @@ class FormUpCountryController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.country.view']);
|
$this->checkAuthorization(auth()->user(), ['forms.country.view']);
|
||||||
|
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
$forms = FormUpCountry::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 = FormUpCountry::whereBetween('tanggal', [$startDate, $closingDate])
|
||||||
->orderBy('tanggal', 'desc')
|
->orderBy('tanggal', 'desc')
|
||||||
->with(['rayon', 'user'])
|
->with(['rayon', 'user'])
|
||||||
->get();
|
->get();
|
||||||
@@ -143,11 +160,25 @@ class FormUpCountryController extends Controller
|
|||||||
'bukti_hotel' => ['nullable', 'file', 'max:51200'],
|
'bukti_hotel' => ['nullable', 'file', 'max:51200'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
$tanggal = Carbon::parse($request->tanggal);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
$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();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use App\Helpers\BudgetHelper;
|
|||||||
use App\Helpers\NotificationHelper;
|
use App\Helpers\NotificationHelper;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use App\Services\BrevoService;
|
use App\Services\BrevoService;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class FormVehicleController extends Controller
|
class FormVehicleController extends Controller
|
||||||
{
|
{
|
||||||
@@ -36,10 +37,26 @@ class FormVehicleController extends Controller
|
|||||||
$this->checkAuthorization(auth()->user(), ['forms.vehicle.view']);
|
$this->checkAuthorization(auth()->user(), ['forms.vehicle.view']);
|
||||||
|
|
||||||
$role = auth()->user()->getRoleNames()[0];
|
$role = auth()->user()->getRoleNames()[0];
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE')); // Starting date from .env for the current month
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE'); // Closing date for the next month
|
$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')
|
->orderBy('tanggal', 'desc')
|
||||||
->with('user')
|
->with('user')
|
||||||
->get();
|
->get();
|
||||||
@@ -129,11 +146,25 @@ class FormVehicleController extends Controller
|
|||||||
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
'bukti_total' => ['nullable', 'file', 'max:51200'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$startDate = date('Y-m-' . env('STARTING_DATE'));
|
$tanggal = Carbon::parse($request->tanggal);
|
||||||
$closingDateNextMonth = date('Y-m-', strtotime('+1 month')) . env('CLOSING_DATE');
|
$startDay = (int) env('STARTING_DATE', 11);
|
||||||
|
$closingDay = (int) env('CLOSING_DATE', 10);
|
||||||
|
|
||||||
if ($request->tanggal < $startDate || $request->tanggal > $closingDateNextMonth) {
|
// Ambil tanggal sekarang untuk tentukan periode berjalan
|
||||||
session()->flash('error', 'Gagal, Input expense sudah melewati periode input 12-10');
|
$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();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -270,16 +270,6 @@
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error checking notifications:', error);
|
console.error('Error checking notifications:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
const periode = document.getElementById('periode');
|
|
||||||
const date = new Date();
|
|
||||||
|
|
||||||
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
||||||
const month = months[date.getMonth()]; // Get the current month's short name
|
|
||||||
const nextMonth = months[(date.getMonth() + 1) % 12]; // Get the next month's short name, wrapping around if necessary
|
|
||||||
const year = date.getFullYear();
|
|
||||||
|
|
||||||
periode.textContent = `${month} (11 ${month} - 10 ${nextMonth} ${year})`;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -306,3 +296,30 @@
|
|||||||
|
|
||||||
resetLogoutTimer();
|
resetLogoutTimer();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const periode = document.getElementById('periode');
|
||||||
|
const date = new Date();
|
||||||
|
|
||||||
|
const currentYear = date.getFullYear();
|
||||||
|
const currentMonthIndex = date.getMonth(); // 0 = Jan, 11 = Dec
|
||||||
|
const currentDay = date.getDate();
|
||||||
|
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||||
|
|
||||||
|
let startMonthIndex, closingMonthIndex, closingYear;
|
||||||
|
|
||||||
|
if (currentDay >= 11) {
|
||||||
|
startMonthIndex = currentMonthIndex;
|
||||||
|
closingMonthIndex = (currentMonthIndex + 1) % 12;
|
||||||
|
closingYear = currentMonthIndex === 11 ? currentYear + 1 : currentYear;
|
||||||
|
} else {
|
||||||
|
startMonthIndex = (currentMonthIndex - 1 + 12) % 12;
|
||||||
|
closingMonthIndex = currentMonthIndex;
|
||||||
|
closingYear = currentYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startMonth = months[startMonthIndex];
|
||||||
|
const closingMonth = months[closingMonthIndex];
|
||||||
|
|
||||||
|
periode.textContent = `${startMonth} (11 ${startMonth} - 10 ${closingMonth} ${closingYear})`;
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user