first(); if ($element->type_of_customer != 1 || $element->solar_power_type != 1) { return false; } // Check 2: Calculate net loan amount (< 5 lakh) $offerId = $application->offer_id ?? null; $net_loan_amount = 0; if (!empty($offerId)) { $active_offer = \App\MerchantOffers::where('id', $offerId)->first(); if ($active_offer) { $loan_amount = $application->loan_amount ?? 0; // Using autoBRE calculation as referenced in DisbursementController $autoBRE = new autoBRE(); $net_loan_amount = $autoBRE->calculateNetLoanAmount($loan_amount, $active_offer); } } if ($net_loan_amount >= 500000) { return false; } // Build payload details $payloadData = [ 'application_id' => $applicationId, 'applicant_signing' => 1, 'co_applicant_signing' => !empty($application->co_applicant_name) ? 1 : 0, 'has_co_applicant' => !empty($application->co_applicant_name) ? true : false, 'type_of_customer' => $element->type_of_customer, 'solar_power_type' => $element->solar_power_type, 'net_loan_amount' => $net_loan_amount, ]; // If all synchronous pre-checks pass, insert job into the database $job = new JobProvider(); $job->insert([ 'application_id' => $applicationId, 'from' => 'autoDCD', 'payload' => json_encode($payloadData), 'available_at' => Carbon::now()->toDateTimeString(), 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), 'is_available' => 0 ]); return true; } catch (\Exception $e) { $cwFactory = new CloudWatchLoggerFactory(); $cwFactory->logger(json_encode([ 'application_id' => $applicationId, 'message' => 'AutoDCD prep exception', 'line' => __LINE__, 'values' => [ 'error_message' => $e->getMessage() ] ])); return false; } } }