@@ -13,6 +13,9 @@ class OpportunityWorkflowTasks
|
||||
public function ensure(Opportunity $record, string $kind, string $title): string
|
||||
{
|
||||
$key = 'portal-opportunity:'.$record->id.':'.$kind.':'.($record->workflow_context['content_revision'] ?? 1);
|
||||
if (isset($record->workflow_context['review_cycle'])) {
|
||||
$key .= ':cycle:'.$record->workflow_context['review_cycle'];
|
||||
}
|
||||
$existing = DB::table('tasks')->where('source_system', 'opportunity-workflow')->where('external_id', $key)->first();
|
||||
if ($existing) {
|
||||
return $existing->id;
|
||||
@@ -32,11 +35,20 @@ class OpportunityWorkflowTasks
|
||||
DB::table('tasks')->where('id', $taskId)->update(['assignee_user_id' => $subject->id, 'status' => 'in_progress', 'version_no' => DB::raw('version_no+1')]);
|
||||
}
|
||||
|
||||
public function closedReviewBinding(Opportunity $record, ?string $id): bool
|
||||
{
|
||||
return $id !== null && DB::table('tasks')->where('id', $id)->where('source_system', 'opportunity-workflow')
|
||||
->where('external_id', 'like', 'portal-opportunity:'.$record->id.':opportunity_review:%')->where('status', 'done')->exists();
|
||||
}
|
||||
|
||||
public function complete(?string $taskId, string $outcome): void
|
||||
{
|
||||
if ($taskId) {
|
||||
// Existing CRM outcome is a varchar(80) summary. The full reason is
|
||||
// retained in the versioned workflow decision and its audit event.
|
||||
$summary = mb_strlen($outcome) > 80 ? mb_substr($outcome, 0, 79).'…' : $outcome;
|
||||
DB::table('tasks')->where('id', $taskId)->where('source_system', 'opportunity-workflow')->whereIn('status', ['open', 'in_progress'])
|
||||
->update(['status' => 'done', 'outcome' => $outcome, 'completed_at' => now(), 'version_no' => DB::raw('version_no+1')]);
|
||||
->update(['status' => 'done', 'outcome' => $summary, 'completed_at' => now(), 'version_no' => DB::raw('version_no+1')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user