fix bug periode

This commit is contained in:
Jagad R R
2025-05-05 19:40:38 +07:00
parent af21c0877d
commit 35ad132607
9 changed files with 270 additions and 72 deletions
@@ -21,6 +21,7 @@ use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Schema;
use App\Models\Kategori;
use App\Models\BudgetControlLog;
use App\Helpers\PeriodeHelper;
class ReportController extends Controller
{
@@ -621,53 +622,60 @@ class ReportController extends Controller
]);
}
public function generateJurnal() {
public function generateJurnal()
{
$params = request()->all();
$kategoris = Kategori::all();
$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'];
$month = $params['month'];
$month = $params['month']; // format: angka atau teks bulan (pastikan valid)
// get last data
$budget = BudgetControlLog::where('cabang_id', $cabang->id)->where('periode_year', $year)->where('periode_month', $month)->orderBy('created_at', 'desc')->first();
// Hitung range periode (11 bulan_ini - 10 bulan_depan)
[$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');
// Fetch all relevant forms in one batch
// Fetch semua forms berdasarkan periode range
$forms = [
'Up Country' => FormUpCountry::whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month)))
->whereYear('tanggal', '=', $year)
->whereIn('status', ['Approved', 'Closed'])
->whereBetween('tanggal', [$startDate, $endDate])
->whereIn('status', ['Approved', 'On Progress'])
->get(),
'Vehicle Running Cost' => FormVehicleRunningCost::whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month)))
->whereYear('tanggal', '=', $year)
->whereIn('status', ['Approved', 'Closed'])
->whereBetween('tanggal', [$startDate, $endDate])
->whereIn('status', ['Approved', 'On Progress'])
->get(),
'Entertainment' => FormEntertaimentPresentation::whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month)))
->whereYear('tanggal', '=', $year)
->whereIn('status', ['Approved', 'Closed'])
->whereBetween('tanggal', [$startDate, $endDate])
->whereIn('status', ['Approved', 'On Progress'])
->get(),
'Meeting / Seminar' => FormMeetingSeminar::whereIn('user_id', $userIds)
->whereMonth('created_at', '=', date('m', strtotime($month)))
->whereYear('created_at', '=', $year)
->whereIn('status', ['Approved', 'Closed'])
->whereBetween('created_at', [$startDate, $endDate])
->whereIn('status', ['Approved', 'On Progress'])
->get(),
];
// Fetch 'Others' forms by kategori
// Forms "Others" dikelompokkan berdasarkan kategori
$otherForms = FormOthers::whereIn('user_id', $userIds)
->whereMonth('tanggal', '=', date('m', strtotime($month)))
->whereYear('tanggal', '=', $year)
->whereIn('status', ['Approved', 'Closed'])
->whereBetween('tanggal', [$startDate, $endDate])
->whereIn('status', ['Approved', 'On Progress'])
->get();
// Precompute totals for each category
// Total nominal per kategori
$nominals = [];
foreach ($kategoris as $item) {
if (isset($forms[$item->name])) {
@@ -687,7 +695,7 @@ class ReportController extends Controller
'month' => $month,
'kategori_bca' => $kategori_bca,
'nominals' => $nominals,
'budget' => $budget
'budget' => $budget,
]);
}
}
@@ -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 FormEntertainmentPresentationController extends Controller
{
@@ -36,10 +37,26 @@ class FormEntertainmentPresentationController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.entertainment.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 = 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')
->with('user')
->get();
@@ -128,11 +145,25 @@ class FormEntertainmentPresentationController 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();
}
@@ -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 FormMeetingSeminarController extends Controller
{
@@ -36,10 +37,26 @@ class FormMeetingSeminarController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.meeting.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 = 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')
->with('user')
->get();
@@ -131,12 +148,25 @@ class FormMeetingSeminarController extends Controller
'bukti_hotel' => ['nullable', 'file', 'max:51200'],
]);
$currentDate = $request->tanggal;
$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 ($currentDate < $startDate || $currentDate > $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();
}
@@ -25,6 +25,7 @@ use App\Helpers\NotificationHelper;
use App\Models\Cabang;
use Illuminate\Support\Facades\Log;
use App\Services\BrevoService;
use Carbon\Carbon;
class FormOtherController extends Controller
{
@@ -33,10 +34,27 @@ class FormOtherController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.other.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 = 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')
->with('user')
->get();
@@ -126,11 +144,25 @@ class FormOtherController 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();
}
@@ -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 FormUpCountryController extends Controller
{
@@ -36,10 +37,26 @@ class FormUpCountryController extends Controller
$this->checkAuthorization(auth()->user(), ['forms.country.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 = 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')
->with(['rayon', 'user'])
->get();
@@ -143,11 +160,25 @@ class FormUpCountryController extends Controller
'bukti_hotel' => ['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();
}
@@ -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();
}