$period, 'year' => $year, 'month' => $month, ]); if ($period === '202505') { // Untuk periode 202505, mulai dari tanggal 9 $startDate = \Carbon\Carbon::createFromDate($year, $month, 9,'Asia/Jakarta'); } else { // Untuk periode lain, mulai dari tanggal 1 $startDate = \Carbon\Carbon::createFromDate($year, $month, 1,'Asia/Jakarta'); } // Tanggal akhir selalu akhir bulan $endDate = \Carbon\Carbon::createFromDate($year, $month, 1)->endOfMonth(); return [ 'start' => $startDate, 'end' => $endDate, ]; } } if(!function_exists('getProvinceCoreName')){ function getProvinceCoreName($code){ return $code; } } if(!function_exists('generatePassword')){ function generatePassword(Account $account) { $customer = $account->customer; $accountNumber = $account->account_number; // Get last 2 digits of account number $lastTwoDigits = substr($accountNumber, -2); // Determine which date to use based on sector $dateToUse = null; if ($customer && $customer->sector) { $firstDigitSector = substr($customer->sector, 0, 1); if ($firstDigitSector === '1') { // Use date_of_birth if available, otherwise birth_incorp_date $dateToUse = $customer->date_of_birth ?: $customer->birth_incorp_date; } else { // Use birth_incorp_date for sector > 1 $dateToUse = $customer->birth_incorp_date; } } // If no date found, fallback to account number if (!$dateToUse) { Log::warning("No date found for account {$accountNumber}, using account number as password"); return $accountNumber; } try { // Parse the date and format it $date = Carbon::parse($dateToUse); $day = $date->format('d'); $month = $date->format('M'); // 3-letter month abbreviation $year = $date->format('Y'); // Format: ddMmmyyyyXX (e.g., 05Oct202585) $password = $day . $month . $year . $lastTwoDigits; return $password; } catch (\Exception $e) { Log::error("Error parsing date for account {$accountNumber}: {$e->getMessage()}"); return $accountNumber; // Fallback to account number } } }