feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
@@ -4,8 +4,10 @@ namespace App\Services\Ai;
|
||||
|
||||
use App\Models\CrmTask;
|
||||
use App\Models\InvestmentSubmission;
|
||||
use App\Models\Lead;
|
||||
use App\Models\SimulationFormDraft;
|
||||
use App\Models\User;
|
||||
use App\Services\CrmNextAction;
|
||||
use App\Services\InvestmentGeography;
|
||||
use App\Services\VirtualDesk;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -152,7 +154,7 @@ class InvestorGuidance
|
||||
->get(['t.id', 't.title', 't.status', 't.due_at', 't.version_no', 't.desk_request_id', 't.accepted_by', 't.accepted_at', 't.assignee_user_id', 'u.name as assignee_name', 't.external_sync_status']);
|
||||
|
||||
return ['version' => $case->version, 'rules_version' => InvestorGuidanceRules::VERSION, 'computed_at' => now()->toIso8601String(),
|
||||
...$context, 'phases' => $phases, 'tasks' => $tasks, 'actions' => $actions, 'can_write' => $this->desk->owns($actor, $case),
|
||||
...$context, 'phases' => $phases, 'tasks' => $tasks, 'actions' => $actions, 'can_write' => ! $case->closed_at && $this->desk->owns($actor, $case), 'can_update_tasks' => ! $case->closed_at,
|
||||
'external_ai' => ['status' => 'not_configured', 'model' => null, 'consulted' => []],
|
||||
'calculator_versions' => ['business_financial_plan' => hash_file('sha256', resource_path('js/lib/business-financial-plan.ts')), 'financial_calculators' => hash_file('sha256', resource_path('js/lib/financial-calculators.ts')), 'project_dossier' => hash_file('sha256', resource_path('js/lib/project-dossier.ts'))],
|
||||
'crm' => ['internal' => 'available', 'external' => 'out_of_scope', 'reason' => 'O acompanhamento usa o CRM interno existente. A sincronização externa está fora desta fase; nenhum contacto, mensagem ou documento é transmitido.']];
|
||||
@@ -235,10 +237,16 @@ class InvestorGuidance
|
||||
$data = Validator::make($input, ['version' => 'required|integer|min:1', 'status' => ['required', Rule::in(['open', 'in_progress', 'done', 'cancelled'])],
|
||||
'reason' => 'required|string|min:3|max:3000', 'assignee_user_id' => 'nullable|integer|exists:users,id', 'due_at' => 'nullable|date|after:now'])->validate();
|
||||
DB::transaction(function () use ($actor, $id, $taskId, $data) {
|
||||
$case = $this->desk->case($actor, $id);
|
||||
$case = $this->desk->case($actor, $id, false, true);
|
||||
$this->desk->assertOpen($case);
|
||||
$candidate = CrmTask::where('desk_case_id', $id)->whereKey($taskId)->firstOrFail();
|
||||
// Match CRM lock order, so two response channels cannot finish each other's only replacement.
|
||||
$lead = $candidate->lead_id === null ? null : Lead::withTrashed()->whereKey($candidate->lead_id)->lockForUpdate()->firstOrFail();
|
||||
$task = CrmTask::where('desk_case_id', $id)->whereKey($taskId)->lockForUpdate()->firstOrFail();
|
||||
abort_unless($task->lead_id === $candidate->lead_id, 409, 'O acompanhamento associado mudou. Recupere a tarefa actual.');
|
||||
abort_unless($actor->can('manage-portal') || (int) $task->getAttribute('assignee_user_id') === $actor->id, 403);
|
||||
abort_unless((int) $task->getAttribute('version_no') === (int) $data['version'], 409);
|
||||
app(CrmNextAction::class)->assertMayFinish($lead, $task, $data['status']);
|
||||
$updates = ['status' => $data['status'], 'version_no' => $data['version'] + 1];
|
||||
if ($data['assignee_user_id'] ?? null) {
|
||||
abort_unless($actor->can('manage-portal'), 403);
|
||||
|
||||
Reference in New Issue
Block a user