copy()->subMonth(); $sixMonthsAgo = $now->copy()->subMonths(6); // Waiting billing: >1 bulan & <6 bulan $billingLogs = RequestLog::where('final_log', 0) ->whereNull('deleted_at') ->whereBetween('submission_date', [$sixMonthsAgo, $oneMonthAgo]) ->where('status', '!=', 'waiting_billing') ->get(); foreach ($billingLogs as $log) { RequestLogHistory::create([ 'request_log_id' => $log->id, 'old_status' => $log->status, 'new_status' => 'waiting_billing', 'notes' => 'Auto update status via cronjob', 'changed_at' => now(), ]); $log->update(['status' => 'waiting_billing']); } // Cancel: >6 bulan $cancelLogs = RequestLog::where('final_log', 0) ->whereNull('deleted_at') ->where('submission_date', '<', $sixMonthsAgo) ->where('status', '!=', 'canceled') ->get(); foreach ($cancelLogs as $log) { RequestLogHistory::create([ 'request_log_id' => $log->id, 'old_status' => $log->status, 'new_status' => 'canceled', 'notes' => 'Auto update status via cronjob', 'changed_at' => now(), ]); $log->update(['status' => 'canceled']); } $this->info("Auto update selesai. Billing: " . count($billingLogs) . ", Cancel: " . count($cancelLogs)); } }