@@ -17,6 +17,13 @@ class ConvertInterestToLead
|
||||
{
|
||||
return DB::transaction(function () use ($interest, $data, $actor) {
|
||||
$interest = InterestRequest::lockForUpdate()->findOrFail($interest->id);
|
||||
$contactConsentIsCurrent = DB::table('consents')->where('interest_request_id', $interest->id)
|
||||
->where('subject_ref', $interest->reference)->where('purpose', 'respond_to_interest')
|
||||
->where('status', 'granted')->whereNotNull('granted_at')->where('granted_at', '<=', now())
|
||||
->whereNull('withdrawn_at')->whereNull('deleted_at')->lockForUpdate()->exists();
|
||||
if (! $interest->privacy_consent || ! $contactConsentIsCurrent) {
|
||||
throw ValidationException::withMessages(['investor_id' => 'O pedido não tem consentimento de contacto activo.']);
|
||||
}
|
||||
$existing = Lead::withTrashed()->where('interest_request_id', $interest->id)->first();
|
||||
if ($existing) {
|
||||
if ($existing->trashed()) {
|
||||
@@ -25,8 +32,8 @@ class ConvertInterestToLead
|
||||
|
||||
return $existing;
|
||||
}
|
||||
if (! $interest->privacy_consent) {
|
||||
throw ValidationException::withMessages(['investor_id' => 'O pedido não tem consentimento de contacto registado.']);
|
||||
if (! is_string($interest->email) || trim($interest->email) === '') {
|
||||
throw ValidationException::withMessages(['investor_id' => 'Confirme um email antes de converter este pedido telefonico num contacto/lead CRM.']);
|
||||
}
|
||||
$email = strtolower(trim($interest->email));
|
||||
$journeyInvestor = DB::table('investor_journeys')->where('interest_request_id', $interest->id)->whereNull('deleted_at')->value('investor_id');
|
||||
|
||||
Reference in New Issue
Block a user